Linux get_opt Sigpause

Source: Internet
Author: User

1. When Linux processes command-line programs, the input parameters can be processed using the GET_OPT library function, which facilitates the production of command-line tools.

2. When the program needs to stop waiting for the signal to end, the usual practice is to use a while (true) loop, so that the program's CPU consumes very high, using the Sigpause function.

sigpause temporarily replaces the signal mask of the calling process with the mask given by mask and then suspends the Process until delivery of a signal whose action is to invoke a signal handler or to terminate a process.

If the signal terminates the process, then sigsuspend() does not return. If the signal is caught, then sigsuspend() returns after the signal handler returns, and the signal mask is Resto

 sigpause  needs to pass in a mask when used,  When the program executes here, Sigpause temporarily replaces the mask of the current process with the incoming mask, and blocks the use of the CPU until a signal outside the mask arrives.  normally,   sigsuspend  () is used in conjunction with < Strong>sigprocmask  (2) in order to prevent delivery of a signal during the execution of a critical code section. The caller first blocks the signals with   Sigprocmask  (2). When the critical code had completed, the caller then waits for the signals by CALLING&NBSP;  Sigsuspend  () With the signal mask is returned by  Sigprocmask  (2) (in the   oldset   argument). 
Sigsuspend (2)  -waits for any signal. It takes a signal mask of signals that is atomically unblocked,

The sigsuspend() function is the modern analogue of the old pause() function.

Major change:two code blocks reversed.

It allows to send your thread to sleep until one of its selected signals occurs. If you want it to sleep until Sigrtmin+1 arrives, you use:

sigfillset(&mask);sigdelset(&mask, SIGRTMIN+1);sigsuspend(&mask);

This blocks every signal except sigrtmin+1.

If you want to sleep until a signal other than sigrtmin+1 arrives, you use:

sigemptyset(&mask);sigaddset(&mask, SIGRTMIN+1);sigsuspend(&mask);

This blocks is only sigrtmin+1.



Linux get_opt sigpause

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.