Skip to content

kill()

Purpose

kill() sends a signal to a process or process group.

Despite its name, it can send any signal, not only termination signals.

#include <signal.h>
#include <sys/types.h>

Prototype

int kill(pid_t pid, int sig);

Minimal Example

if (kill(child_pid, SIGTERM) < 0) {
    perror("kill");
    return -1;
}

Common Pitfalls

  • Assuming the target process exits immediately.
  • Not checking permissions.
  • Sending signals to the wrong process group by using negative PID values incorrectly.
  • Forgetting to call waitpid() after terminating a child.