On UNIX systems, terminating programs involves sending signals, such as SIGTERM or SIGKILL1, to the target process. SIGTERM allows a process to gracef

Pseudo Graceful Process Termination through Code Injection

submited by
Style Pass
2024-02-27 17:30:13

On UNIX systems, terminating programs involves sending signals, such as SIGTERM or SIGKILL1, to the target process. SIGTERM allows a process to gracefully handle the termination signal, whereas SIGKILL abruptly ends the process. After termination, the parent process takes charge by reading the exit status and acting accordingly. An exit code of 0 signifies success, whereas other codes denote failures, including termination by a signal or application errors.

However, what if the need arises to forcefully terminate a process, disguising it as a successful exit? I came across this need recently while observing a long-running process that blocked further work. It made no progress, and I was tempted to just kill2 it. Since the parent process would detect the non-zero exit code, there was a high likelihood of making things worse.

This got me thinking - how can we build a tool to stop a process forcefully but make it look like a successful termination? As far as I know, Linux doesn’t provide an API to perform such a kill. So I decided to take a different route and make the process terminate itself with a zero exit code using code injection.

Leave a Comment