UNIX advanced Environment Programming-signal correlation function Note __php

Source: Internet
Author: User
Tags signal handler

1. How to view signal correlation function

Mans Signal

See ALSO (My Os:ubuntu 14.) 04 64-bit)

ALSO
       Kill (1), Alarm (2), Kill (2),  KILLPG (2),  pause (2),  sigaction (2), sig‐ NALFD (2
       ),  sigpending (2), Sigprocmask (2), Sigsuspend (2), bsd_signal (3),
       raise (3),  Siginterrupt (3),   Sigqueue (3),   Sigsetops (3),   Sigvec (3),
       sysv_signal (3), Signal (7)

Of course, the next notes are programmed in the UNIX advanced environment, and other functions can be accessed by man


2. function notes

Name Kill-send signal to a process//send signal to processes or process groups, and a KILL command with the same name synopsis #include <sys/types.h>

#include <signal.h> int Kill (pid_t pid, int sig); NAME        Raise-send A signal to the caller//process sends a signal to itself, equivalent to Kill (Getpid (), Signo) synopsi S        #include <signal.h>        int raise (int

SIG);  name        alarm-set A alarm clock for delivery of a signal   #include <un  istd.h>        unsigned int alarm (unsigned int seconds); Seconds is set to 0 to cancel the previous alarm, leaving the remaining value to the return value  name        pause-wait for signal//pause to make the calling process Suspend until a signal is captured synopsis        #include <unistd.h>      & nbsp  int pause (void); Pause only returns if a signal handler is executed and returned. Return value: -1,errno set to Eintr 1.  name        Sigprocmask-examine and change blocked signals//detects or changes the current signal screen Word, note that this function is defined for single-threaded processes only synopsis    & nbsp;   #include <signal.h>        int sigprocmask (int how, const sigset



_t *set, sigset_t *oldset); Remember the last sentence, after calling Sigprocmask if there are any pending signals that are not blocked, then at least one of them will be delivered to the process   multithreaded process before the Sigprocmask returns, and the thread must use the Pthread_sigmask

The NAME
       sigpending-examine pending signals  //sigpending function returns the set of signals that are blocked pending sending to the process
Synopsis
       #include < signal.h>
       int sigpending (sigset_t *set);

Sigaction Detailed:

function: Check or modify the processing action associated with the specified signal (both operations can be done at the same time)

int sigaction (int signo,const struct sigaction *restrict Act,

struct sigaction *restrict oact);

Signo: Of course, the signal is specified.

ACT: New signal processing related

Oact: getting old signal processing related


Sigaction Structure Body Content:

struct sigaction{
  void (*sa_handler) (int);
   sigset_t Sa_mask;
  int Sa_flag;
  void (*sa_sigaction) (int,siginfo_t *,void *);

The Sa_handler field contains the address of a signal capture function

The Sa_mask field describes a set of signals that is added to the process's signal mask before the signal capture function is invoked. Resets the process's signal mask word back to its original value only when it is returned from the signal capture function. (Note that this is the point)

Sa_flag is an option that mainly understands that two

sa_interrupt system calls that are interrupted by this signal are not automatically restarted
Sa_restart system calls that are interrupted by this signal automatically restart

sa_siginfo provide additional information, A pointer to the SIGINFO structure and a pointer to the process context identifier The
last parameter is useful for the queuing signal function, see the following signal queuing related knowledge

#include <signal.h>
int sigsuspend (const sigset_t *sigmask);
See the UNIX Advanced Environment Programming 286 page, which explains why Sigsuspend is present, the most important of which is its atomic operation (first recover the signal screen word and then make the process hibernate (accurately suspend)) the signal screen word for the process is set to the Sigmask point value. Return conditional signal occurs, and the signal is not shielded signal must be processed, and the processing function returned after Sigsuspend returned after return sigsuspend setting invalidation, the process of the signal screen Word set to call Sigsuspend before the function returned to the caller, Always returns-1 and sets errno to EINTR (for system calls that are interrupted)

#include <stdlib.h>
void abort (void);         Causes the program to terminate abnormally, sending the SIGABRT signal to the calling process

Signal Queuing Knowledge: Specify the SA_SIGINFO flag when using the Sigaction function to install a signal handler. Provides a signal processing function in the Sa_sigaction member of the Sigaciton structure, rather than the usual Sa_handler field. Send a signal using the Sigqueue function


#include <signal.h>
int sigqueue (pid_t pid,int signo,const Union sigval value);
Sends the SIGNO signal to the PID process, uses the value parameter to pass the integer value to the signal processing function and the pointer value signal queue has the size limit, cannot be infinite queues, exceeds the limit, errno is set to Eagain


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.