For more half-baked ideas, see the ideas tag
I’m sure you’ve sat there waiting for some long compile to finish. It’s just started the tests, but you don’t want it to do the tests, just finish compiling dammit!
My half-baked idea is this: sending a special signal to a process (SIGOK
) should kill the process, but the process should return 0 (ie. non-error exit).
Extending what is already UNIX’s most esoteric and least well-designed interface with a weird special case just to improve shell UI sounds a bit risky to me.
I started trying a guru-mode systemtap script to inject a SIGKILL, then catch the process in kernel do_exit() and squash the exit code to 0. However, the obvious “$code = 0” is not enough to hide the signal, by my experiment, so it may need to modify current->signal or something too.
It’s much simpler to just inject a call with gdb, like:
gdb -ex ‘p _exit(0)’ -ex quit -p $TARGET_PID
Of course this only works for a single process. If you want to “SIGOK” a whole process group, or a target already under ptrace, then I’d look back at a systemtap approach. (Or lobby for a real SIGOK — good luck…)
Note the GNU coreutils timeout command since version 8.21 has a –preserve-status option for running commands that can run for an indeterminate amount of time. I.E. run until told to stop. You tell the timeout group to stop with the ALRM signal, so something like:
timeout –preserve-status 365d my_command & pid=$!
…
kill -ALRM $pid