0

I am writing a C program that uses fork(), execvp() for child process. I want to stop, continue and kill a child process, how can I handle it ? I don't know much about signals.

Emin Çiftçi
  • 139
  • 2
  • 16
  • 3
    `kill(pid, SIGSTOP)` will stop the process, `kill(pid, SIGCONT)` will continue it. What more do you need to know? – Barmar Jun 09 '16 at 00:44

1 Answers1

0

Call the signal function within a process to setup a signal handler, a function that will be called when that process receives the specific signal you specify.

Here's an example signal handler function for the SIGUSR1 signal:

static void usr1_signal_handler(int signo)
{
    printf("Received SIGUSR1!\n");
    finish_up = true;
}

and an example of how to set it up:

if (signal(SIGUSR1, usr1_signal_handler) == SIG_ERR) {
    printf("An error occurred while setting a signal handler.\n");
}

You can signal a process using the kill function:

kill(pid, SIGUSR1);

In this case, pid could be the process id you receive when you call fork.

Gavin Higham
  • 89
  • 1
  • 4