[PATCH] timeout: Add support for "-k" parameter.
Denys Vlasenko
vda.linux at googlemail.com
Fri Dec 17 22:10:26 UTC 2021
On Sat, Oct 9, 2021 at 1:28 PM Matthew Slowe <foo at mafoo.org.uk> wrote:
> Add support for GNU coreutils "-k" parameter to timeout applet.
>
> This patch moves the timing and process checking code into a separate
> reusable function and adds a optional second timeout which will send a
> SIGKILL to the process if it's still alive.
/* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */
- while (1) {
- sleep1();
- if (--timeout <= 0)
- break;
- if (kill(parent, 0)) {
- /* process is gone */
+ if (timeout_wait(timeout, pid) == EXIT_SUCCESS)
You waiting for a wrong process: should be "parent", not "pid"
(pid is 0 here).
+ return EXIT_SUCCESS;
+ kill(parent, signo);
+
+ if (kill_timeout > 0) {
+ if (timeout_wait(kill_timeout, pid) == EXIT_SUCCESS)
Here too.
return EXIT_SUCCESS;
- }
+ kill(parent, SIGKILL);
}
- kill(parent, signo);
More information about the busybox
mailing list