My C notes

Source: Internet
Author: User

My own notes are messy.

 

Syntax: If the parameter is of the const type, it only indicates that the parameter cannot be modified in the implementation of this function. It does not mean that the input parameter type must be of the const type.

IntSigsuspend(Const sigset_t * sigmask );

Code snippet:

sigset_t zeromask;sigemptyset(&zeromask);sigsuspend(&zeromask);

 

Signal Inheritance Problem: The child process inherits the signal mask test address of the parent process: http://blog.chinaunix.net/uid-29100821-id-4018170.html

Theory Description: http://blog.csdn.net/lihuibo128/article/details/8556669

 

UNIX read/write functions: open, write, read

(Http://www.cnblogs.com/Pierre-de-Ronsard/archive/2012/07/09/2582417.html

 

Experiment 1: signal shielding

1. Construct a process: the process sets a processing function for a signal, simulates the signal processing, and checks whether it is as expected.

2. Construct a process: the process sets the processing function for a signal and uses sigprocmask to set it. The process shields the signal, simulates the signal, and checks whether other signals are used as expected, check if as expected

You can understand the functions of the sigprocmask function.

Sigpromask: used to set the signal shielding of the process, which signals are not responded by the process, and the handler of the signal is set in time.

Lab 1 extends knowledge

A group of operations related to the signal set are:

Header file # include <signal. h> sigemptyset (sigset_t * Set) initializes the signal set specified by the set, and all signals in the signal set are cleared. After sigfillset (sigset_t * Set) calls this function, set points to 64 types of signals supported by Linux. sigaddset (sigset_t * Set, int SIGNUM) adds SIGNUM signals to the signal set points to. sigdelset (sigset_t * set, int SIGNUM) deletes the SIGNUM signal in the Set signal set. sigismember (const sigset_t * Set, int SIGNUM) determines whether the signal SIGNUM is in the Set signal set. Int sigaction (INT Sig, const struct sigaction * Act, struct sigaction * oact) checks, modifies the signal response associated with the specified signal. Lab 1 extends knowledgeInt sigprocmask (INT how, const sigset_t * restrict set, sigset_t * restrict oldset); If the parameter how is sig_block, this function will append the signal shielding set of the second parameter to the previous signal shielding set if it is sig_unblock, this function sets the intersection of the new signal shielding set (the complement set of the original mask and the second parameter set. If it is sig_setmask, this function will clear the original signal shielding set, set the signal shielding set of the second parameter as the new signal shielding Set Experiment 2: Test to shield a signal first, allow response to this signal again (only one response is generated)
Int main () {sigset_t sigset, oldmask; signal (SIGUSR1, proc_usr1); sigprocmask (0, null, & oldmask); sigaddset (& sigset, SIGUSR1); sigprocmask (sig_block, & sigset, null); pr_mask ("Block SIGUSR1"); sleep (12); sigprocmask (sig_setmask, & oldmask, null); // set the new blocked word to oldmask.
// Sigprocmask (sig_unblock, & sigset, null); // clear the blocked characters pr_mask ("unblock SIGUSR1"); sleep (12); Return 0 ;}

Run to generate a SIGUSR1 signal

Output:

Block SIGUSR1:SIGUSR1 proc_usr1Unblock SIGUSR1:

Sigpending (sigset_t * Set): obtains the signal shielding characters of the current process for personal understanding. This function has the same functions as sigprocmask (0, null, sigset_t * Set) sigsuspend ();

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.