Linux Signal Processing

Source: Internet
Author: User

A signal is a software interruption. When a program receives a signal, it calls the corresponding processing function (if registered ).

Void (* signal (int signum, void (* handler) (int); -- set the signal processing method void foo (int arg), a prototype of the signal processing function ); the signal defined by the system is/* Signals. */# define SIGHUP1/* Hangup (POSIX ). */# define SIGINT2/* Interrupt (ANSI ). */# define SIGQUIT3/* Quit (POSIX ). */# define SIGILL4/* Illegal instruction (ANSI ). */# define SIGTRAP5/* Trace trap (POSIX ). */# define SIGABRT6/* Abort (ANSI ). */# define SIGIOT6/* IOT trap (4.2 BSD ). */# define SIGBUS7/* BUS error (4.2 BSD ). */# define SIGFPE8/* Floating-point exception (ANSI ). */# define SIGKILL9/* Kill, unblockable (POSIX ). */# define SIGUSR110/* User-defined signal 1 (POSIX ). */# define SIGSEGV11/* Segmentation violation (ANSI ). */# define SIGUSR212/* User-defined signal 2 (POSIX ). */# define SIGPIPE13/* Broken pipe (POSIX ). */# define SIGALRM14/* Alarm clock (POSIX ). */# define SIGTERM15/* Termination (ANSI ). */# define SIGSTKFLT16/* Stack fault. */# define SIGCLDSIGCHLD/* Same as SIGCHLD (System V ). */# define SIGCHLD17/* Child status has changed (POSIX ). */# define SIGCONT18/* Continue (POSIX ). */# define SIGSTOP19/* Stop, unblockable (POSIX ). */# define SIGTSTP20/* Keyboard stop (POSIX ). */# define SIGTTIN21/* Background read from tty (POSIX ). */# define SIGTTOU22/* Background write to tty (POSIX ). */# define SIGURG23/* Urgent condition on socket (4.2 BSD ). */# define SIGXCPU24/* CPU limit exceeded (4.2 BSD ). */# define SIGXFSZ25/* File size limit exceeded (4.2 BSD ). */# define SIGVTALRM26/* Virtual alarm clock (4.2 BSD ). */# define SIGPROF27/* Profiling alarm clock (4.2 BSD ). */# define SIGWINCH28/* Window size change (4.3 BSD, Sun ). */# define SIGPOLLSIGIO/* Pollable event occurred (System V ). */# define SIGIO29/* I/O now possible (4.2 BSD ). */# define SIGPWR30/* Power failure restart (System V ). */# define SIGSYS31/* Bad system call. */# define SIGUNUSED31 # define_NSIG65/* Biggest signal number + 1 (including real-time signals ). */# define SIGRTMIN (_ libc_current_sigrtmin () # define SIGRTMAX (_ libc_current_sigrtmax ()) Send signal to process (on Terminal)Kill-s signal pid -- the value of signal is the valid value of kill-s 9 pid in the list above -- this command ends the specified process. The following example shows the signal received by the process.
#include <unistd.h>#include <stdio.h>#include <signal.h>void handler(int arg){    printf("get signal %d\n", arg);    }int main(){    int i;    for (i=0; i<SIGRTMAX; i++)        signal(i, handler);    while(1)    {        pause();    }    return 0;}

 

You can end it with the kill-s 9 pid. Kill is also a callable APIInt kill (pid_t pid, int sig); kill () can be used to send signals specified by the sig parameter to the process specified by the pid parameter. The pid parameter has several situations: pid> 0 sends the signal to the process with the pid ID. Pid = 0 send the signal to all processes in the same process group as the current process pid =-1 send the signal to all processes in the system pid <0 send the signal to the Process Group ID pid absolute value all processes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.