• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

Killing an exec'ed process

I have installed a signal handler using sigaction to catch SIGTERM. However the main process vforks, and then execs a new process in the resulting child process.

Is there any way to kill that process which has been exec'ed ? From all the man pages, I know that the exec set of calls resets any signal's dispositions to their default handlers.

Any pointers ?
1 Solution
Since you know the process number of the child from the return value of vfork(), you can send the child a SIGTERM.

The code would look something like this:

pid_t child_pid=-1;


if(child_pid == 0) {
    /* this is the child */
} else if(child_pid < 0) {
    /* an error occurred */


void handler(int mysig) {
    if(child_pid > 0)
        kill(child_pid, mysig)


signal(SIGTERM, handler);

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now