Linux application development-signal programming

Source: Internet
Author: User

Linux application Development-signal programming

one signal for interprocess communication

The signal is defined under/usr/include/asm/signal.h.

The common signals are:

Sigkill Kill Process

Sigstop pausing a process

Notifies the parent process when a SIGCHLD child process stops or ends


Two-related functions


Send Signal

Function name Kill

function prototype int Kill (pid_t pid, int sig)

function function sends a signal to any process and process group

Owning header file
#include <sys/types.h>
#include <signal.h>

return value
Successful return 0
Failed return-1

Parameter description


pid > 0 PID parameters point to the process of receiving the signal
PID = 0 signal is sent to each process in the process group
PID = 1 signal is sent to every process that has permission to send a signal, in addition to the INIT process
PID <-1 signal sent to process group PID-pid Process

SIG indicates the signal to be sent


Processing signal

Function name Signal

Function prototype
typedef void (*sighandler_t) (int)
sighandler_t signal (int signal, sighandler_t handler)

function function set the signal processing mode

Owning header file
#include <signal.h>

return value
function pointers for successful return processing
Failed to return Sig_err


Parameter description
Signal the signal to be processed
Handler:
Sig_ign: Ignore this signal, do not process
SIG_DFL: Handing over to kernel processing
User-defined function handling

Linux application development-signal programming

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.