"Linux Learning" Countdown exit, when the process received SIGUSR1 signal start Countdown, 3 seconds after exiting the program.

Source: Internet
Author: User

Topic 3:

Write a program to implement the countdown Exit function, when the process receives the SIGUSR1 signal to start the countdown, 3 seconds after exiting the program.
The process of requiring output from the terminal to receive a signal and start the countdown
Such as:
The process is terminating in 3 sec ...
The process is terminating in 2 sec ...
The process is terminating in 1 sec ...

1#include <sys/types.h>2#include <unistd.h>3#include <signal.h>4#include <stdlib.h>5#include <string.h>6#include <stdio.h>7#include <errno.h>8#include <signal.h>9 Ten intG_tag; One  A voidMyhandle (intnum) - { -printf"recv signal ID num:%d \ n", num); the     if(num = =Ten) -     { -G_tag =0; -     } + } -  + intMainvoid) A { at  -G_tag =1; -  -      -     if(Signal (SIGUSR1, myhandle) = =Sig_err) -     { inPerror ("Signal Err"); -         return 0; to     } +      -      while(1) the     { *         if(G_tag = =0) $         {Panax Notoginsengprintf"The process is terminating in 3 sec ... \ n"); -Sleep1); theprintf"The process is terminating in 2 sec ... \ n"); +Sleep1); Aprintf"The process is terminating in 1 sec ... \ n"); theSleep1); +              Break; -         } $     } $  -      -     return 0; the}

"Linux Learning" Countdown exit, when the process received SIGUSR1 signal start Countdown, 3 seconds after exiting the program.

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.