Explain kill() and its possible return values?

There are four possible results from this call:‘kill()’ returns 0. This implies that a process exists with the given PID, and the system would allow you to send signals to it. It is system-dependent whether the process could be a zombie.‘kill()’ returns -1, ‘errno == ESRCH’ either no process exists with the given PID, or security  enhancements are causing the system to deny its existence. (On     some systems, the process could be a zombie.)‘kill()’ returns -1, ‘errno == EPERM’ the system would not allow you to kill the specified process. This means that either the process exists (again, it could be a zombie) or draconian security enhancements are present (e.g. your process is not allowed to send signals to *anybody*).‘kill()’ returns -1, with some other value of ‘errno’ you are in trouble! The most-used technique is to assume that success or failure with ‘EPERM’ implies that the process exists, and any other error implies that it doesn't.An alternative exists, if you are writing specifically for a system (or all those systems) that provide a ‘/proc’ filesystem: checking for the existence of ‘/proc/PID’ may work.

Showing Answers 1 - 7 of 7 Answers

harish

  • Oct 7th, 2006
 

kill is a system call that allows a user process to send signals to another process.generally its the kernel that sends signals to processes.

  Was this answer useful?  Yes

Kill is one of the command in UNIX/LINux which allow user to kill/terminate one process ID or multiple processes IDs.
Syntax:

$kill -[options] PID

$kill -9 754425

The kill command send the specified signal to the specified process or process group

  Was this answer useful?  Yes

csbhaskar

  • Mar 3rd, 2011
 

As we all know kill command sends a signal to the kernel. This signals are of 64 types. To list all these signals you can use kill -l. Signal no 1 -31 can be invoked by user, whereas, signal no 34-64 are controlled by kernel. The signal nos. 32-33 are reserved for future purpose. If any signals apart from existing signals are developed, the signal numbers 32 and 33 will be allotted to it. General syntax for kill is:

                    kill -[signal number] pid

While sending the kill signal, it may basically result in two:
1. Success : returns a value 0
2. Failure: returns a value 1. In this case the kill signal is not actually send. Instead, it generates errno, which can have three possible values:
     EINVAL  : The value of sig is an invalid or unsupported signal number.

  EPERM        :  The user ID of the sending process is not privileged; its real or effective user ID does not match the real or saved user ID of the receiving process. Or, the process does not have permission to send the signal to any receiving process.

  ESRCH        :   No process or process group can be found that corresponds to the one that pid specifies.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions