/* * Sample program for kill system call - No.37 * * kill - send signal to a process * * Synopsis * #include * #include * * int kill(pid_t pid, int sig); * * Description * The kill system call can be used to send any signal to any process * group or process. * * If pid is positive, then sig is sent to pid. * * If pid equals 0, then sig is sent to every process in the process group * of the current process. * * If pid equals -1, then sig is sent to every process except for process * 1 (init), but see below. * * If pid is less than -1, then sig is sent to every process int the * process group -pid. * * If sig is 0, then no signal is sent, but error checking is still * performed. * * Signals - * SIGHUP 1 * Hangup (POSIX). * * SIGINT 2 * Interrupt (ANSI). * * SIGQUIT 3 * Quit (POSIX). * * SIGILL 4 * Illegal instruction (ANSI). * * SIGTRAP 5 * Trace trap (POSIX). * * SIGABRT 6 * Abort (ANSI). * * SIGIOT 6 * IOT trap (4.2 BSD). * * SIGBUS 7 * BUS error (4.2 BSD). * * SIGFPE 8 * Floating-point exception (ANSI). * * SIGKILL 9 * Kill, unblockable (POSIX). * * SIGUSR1 10 * User-defined signal 1 (POSIX). * * SIGSEGV 11 * Segmentation violation (ANSI). * * SIGUSR2 12 * User-defined signal 2 (POSIX). * * SIGPIPE 13 * Broken pipe (POSIX). * * SIGALRM 14 * Alarm clock (POSIX). * * SIGTERM 15 * Termination (ANSI). * * SIGSTKFLT 16 * Stack fault. * * SIGCLD SIGCHLD * Same as SIGCHLD (System V). * * SIGCHLD 17 * Child status has changed (POSIX). * * SIGCONT 18 * Continue (POSIX). * * SIGSTOP 19 * Stop, unblockable (POSIX). * * SIGTSTP 20 * Keyboard stop (POSIX). * * SIGTTIN 21 * Background read from tty (POSIX). * * SIGTTOU 22 * Background write to tty (POSIX). * * SIGURG 23 * Urgent condition on socket (4.2 BSD). * * SIGXCPU 24 * CPU limit exceeded (4.2 BSD). * * SIGXFSZ 25 * File size limit exceeded (4.2 BSD). * * SIGVTALRM 26 * Virtual alarm clock (4.2 BSD). * * SIGPROF 27 * Profiling alarm clock (4.2 BSD). * * SIGWINCH 28 * Window size change (4.3 BSD, Sun). * * SIGPOLL SIGIO * Pollable event occurred (System V). * * SIGIO 29 * IO now possible (4.2 BSD). * * SIGPWR 30 * Power failure restart (System V). * * SIGSYS 31 * Bad system call. * * SIGUNUSED 31 * * _NSIG 64 * Biggest signal number + 1 * (including real-time signals). * */ #include #include main() { int pid; switch (pid = fork()) { case -1: exit(1); break; case 0: for(;;) printf("child\n"); break; default: sleep(1); kill(pid, SIGKILL); printf("child process terminated\n"); break; } exit(0); }