Linux signal (3): Kill and raise

Source: Internet
Author: User

1. Function Description:

Kill and raise are used to send signals:

Kill sends signals to processes or process groups;

Raise sends the signal to the process itself.

Their prototype is as follows:

# Include <signal. h>

Int kill (pid_t PID, int signo );
Int raise (INT signo );

If the call succeeds, 0 is returned. If the call fails,-1 is returned.

From the prototype, we can see that the raise function can be implemented through kill.

Raise (signo );

It is equivalent:

Kill (getpid (), signo );

2. PID parameters:

The PID parameter in the kill function, which has the following four situations:

  • PID> 0: send the signal to the process whose ID is PID.
  • PID = 0: send the signal to all processes (excluding kernel and init processes) in the same process group of the sending process ). in this case, the sender must have the permission to send signals to these processes.
  • PID <0: send the signal to all processes whose process group ID is equal to the absolute value of PID (excluding kernel processes and init processes ). in this case, the sender must have the permission to send signals to these processes.
  • PID =-1: send the signal to all processes on the system that have the permission to send the signal to the sending process (excluding the kernel process and INIT process ).

3. signo parameters:

Posix.1 defines a signal numbered 0 as an empty signal. if the signo parameter is 0, 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.