Linux signal (1) -- kill function, linuxkill

Source: Internet
Author: User

Linux signal (1) -- kill function, linuxkill

There is no good or bad thing in the world. It depends on how we think about it. -- Scene 2 of the second act of Hamlet

Ilocker: Follow Android Security (New entry, 0 basics) QQ: 2597294287

1 # include <signal. h> 2 int kill (pid_t pid, int signo );

Sends signals to a specified process or process group. 0 is returned for success, and-1 is returned for error.

  • Pid> 0: send the signal to the process whose ID is pid.
  • Pid = 0: send the signal to all processes in the same process group of the sending process.
  • Pid <0: sends a signal to all processes whose process group ID is equal to the absolute value of the pid.
  • Pid =-1: sends signals to all processes in the system.

All processes in the preceding section do not include system processes.

In addition, the process that calls the kill function must have the permission to send signals to the target process. A non-root user can only send signals to a process that has the same user ID as the process that calls the kill function.

If the value of signo is 0, it indicates an empty signal. kill does not send the actual signal, but can be used to determine whether the specified process still exists. If an empty signal is sent to a non-existent process, kill returns-1, and errno is set to ESRCH (indicating that the process specified by the pid or the process group does not exist ).

Other errno: "EINVAL: the specified singo is invalid; EPERM: the permission is insufficient ".

It is not an atomic operation to check whether a process exists. When a kill is returned, the existing process may be terminated. In addition, the system will reuse the pid, so the process we specify the pid is not necessarily the process to be tested. Therefore, this test is not reliable.

Learning Materials: Advanced Programming in unix environment

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.