Process suspend function Pause

Source: Internet
Author: User

Consider the use of the pause function:
1#include <stdio.h>2#include <signal.h>3#include <unistd.h>4 voidSignhand (intSigno)5 {6 inti;7 for(i=0;i<Ten; i++)8 {9printf"signhand number is%d\n", i);TenSleep1); One } A } - intMain () - { the inti; - signal (sigalrm,signhand); -Alarm3); - pause (); Process hangs + for(i=0;i<Ten; i++) - { +printf"main number is%d\n", i); ASleep1); at } - return 0; -}

Program running results: (in fact, the program is executed to pause after waiting for the signal to trigger, after the signal triggered, the execution of signal function, after the execution of the signal function, return to the main function to continue execution!) )

Signhand number is 0Signhand Number is 1Signhand Number is 2Signhand Number is 3Signhand Number is 4Signhand Number is 5Signhand Number is 6Signhand Number is 7Signhand Number is 8Signhand Number is 9Main number is 0Main number is 1Main number is 2Main number is 3Main number is 4Main number is 5Main number is 6Main number is 7Main number is 8Main number is 9

Look at a cow x program: We set the 10s, the process sends itself a SIGALRM signal

1#include <stdio.h>2#include <signal.h>3#include <unistd.h>4 voidSignhand (intSigno)5 {6         inti;7          for(i=0;i<5; i++)8         {9printf"signhand number is%d\n", i);TenSleep1); One         } A } - intMain () - { the         inti; - signal (sigalrm,signhand); -AlarmTen); -          for(i=0;i<5; i++) +         { -printf"main number is%d\n", i); +Sleep1); A         } at         return 0; -}

The results of this program are as follows:

1  is 0 2  is 1 3  is 2 4  is 3 5  is 4

You can see that the function does not trigger the function of the signal, in the main function of the operation of the operation of no signal at all!

Process suspend function Pause

Related Article

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.