Signal Signal processing function

Source: Internet
Author: User

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

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.