kill call on self is failing with ESRCH

I have a situation that I cannot understand. I am running the
following code:

rc = kill (0, SIGTERM); //send out the SIGTERM signal

if(-1 == rc) {
syslog(LOG_INFO, “ppselftestctrl::systemShutDownMode( ) kill() call
failed: %s”, strerror(errno));
}

This should send a SIGTERM to the processing making the kill call.
This works well 99% of the time, but occasionally (like once a month)
it fails and I get the message “kill() call failed: No such process”,
which corresponds to errno==ESRCH.

Obviously, the process exists, or else it wouldn’t be there to make
the kill call or output that message.

Can anyone offer any advice, either on debug methods or what the
problem could be - would it help to get my PID and then send a kill
to that?

Thanks in advance,
Geoff

glansberry <glansberry@gmail-dot-com.no-spam.invalid> wrote:

kill( 0, SIGNAL) doesn’t explicitly send the signal to the
calling process, it sends the process group of the calling
process. I still wouldn’t expect an ESRCH, but there might
be a race condition that causes this to happen.

If you want to kill your own process, I think raise() would
be the preferred choice.

Or, kill( getpid(), SIGNAL).

But, kill( 0, SIGNAL ) != kill( getpid(), SIGNAL).

-David

I have a situation that I cannot understand. I am running the
following code:

rc = kill (0, SIGTERM); //send out the SIGTERM signal

if(-1 == rc) {
syslog(LOG_INFO, “ppselftestctrl::systemShutDownMode( ) kill() call
failed: %s”, strerror(errno));
}

This should send a SIGTERM to the processing making the kill call.
This works well 99% of the time, but occasionally (like once a month)
it fails and I get the message “kill() call failed: No such process”,
which corresponds to errno==ESRCH.

Obviously, the process exists, or else it wouldn’t be there to make
the kill call or output that message.

Can anyone offer any advice, either on debug methods or what the
problem could be - would it help to get my PID and then send a kill
to that?

Thanks in advance,
Geoff


David Gibbs
QNX Training Services
dagibbs@qnx.com