Linux Signal (6): Kill and raise functions to send signals __oracle

Source: Internet
Author: User

1. Function Description:

Kill and raise are used to send signals:

Kill sends a signal to a process or process group, not only to abort the process, but to send other signals to the process;

The raise sends the signal to the (process) itself.

Their prototypes are as follows:

#include <signal.h>

#include <sys/types.h>

int Kill (pid_t pid,/* Indicates the signal process number to send * *

int signo);/* Signal * *
int raise (int signo);/* Signal//

Success returns 0, error returns-1
As you can see from the prototype, the raise function can be implemented by kill.

Raise (Signo);

Equivalent to:

Kill (Getpid (), signo);


2. Parameter description

PID Parameters:

The PID parameter in the Kill function, which has the following 4 kinds of conditions:

PID > 0: This signal is sent to the process with the process ID PID.
PID = 0: Sends the signal to all processes (excluding kernel processes and init processes) that belong to the same process group as the sending process. At this point, the sending process must have the right to send signals to these processes.
PID < 0: Send this signal to all processes whose process group ID equals PID absolute value (excluding kernel processes and init processes). At this point, the sending process must have the right to send signals to these processes.
PID = = 1: Sends the signal to all processes on the system where the sending process has permission to send signals to them. (excluding kernel processes and init processes).

Signo Parameters:

POSIX.1 defines a signal that is numbered 0 as an empty signal. If the Signo parameter is 0, the kill still performs a normal error check but does not send a signal. This is used to determine whether a process exists.

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.