A soft interrupt signal (signal, also referred to as a signal) is used to notify the process that an asynchronous event has occurred. Processes can send soft interrupt signals to each other through system call kill.
The kernel can also send a signal to the process because of an internal event, notifying the process that an event has occurred.
Note that the signal is only used to notify a process of what has happened and does not pass any data to the process.
Kill-l # #可以列举当前系统支持的信号
void (*signal (int sig, Void (*func) (int))) (int) # #singal prototypes
Let's see an example.
1#include <stdio.h>2#include <pthread.h>3#include <unistd.h>4#include <signal.h>5 6 BOOLIs_quit =false;7 8 voidSignal_handle (intsignal_num) {9printf"receive the Signal sigusr1\n");TenIs_quit =true; One } A - void* Do_work (void*Arg) - { the intnum =0; -printf"start\n"); - while(!is_quit) { -num++; +printf"running%d ... \ n", num); -Sleep2); + } Aprintf"end\n"); at returnNULL; - } - - intMainintargcChar*argv[]) - { - pthread_t pid; inPthread_create (&pid, NULL, do_work, NULL); - signal (SIGUSR1, signal_handle); to pthread_join (PID, NULL); + return 0; -}
More signal functions Reference: http://blog.csdn.net/zzyoucan/article/details/9235685
Signal Signal processing function