This is a CLI tool to exit any process with arbitrary exit code.
Instead of killing a process, do you ever want to "exit" it? pexit comes to the rescue!
With some prerequisites (see below), you can force any process to exit, even with your specified exit code!
- For fun.
- In the case of running a pipelined job
foo && bar, simply killingfoowill cause it to exit with error andbaris not executed. Usingpexit, however, can makefooexit with success so thatbarcontinues to be executed.
pip install pexit
pexit <pid> [<exit_code>]
# The default value for <exit_code> is 0 (meaning success)
pexitrelies on the system callptrace, which does not exit in some systems (like Windows).- To be able to
ptraceany process, you may need root privilege (sudo pexit ...) or allow this in system setting (sudo sysctl kernel.yama.ptrace_scope=0).
This project refers to the following sources:
- A great example showcasing how to use
ptraceto runprintf: https://github.com/eklitzke/ptrace-call-userspace/blob/master/call_fprintf.c