Operating System - HP-UX
1751711 Members
5279 Online
108781 Solutions
New Discussion юеВ

Re: Problem with kill signal in C code

 
SOLVED
Go to solution
Curtis Deese
Frequent Advisor

Problem with kill signal in C code

I am running some C code with the following version of cc: HP C/aC++ B3910B A.06.25 [Nov 30 2009]. My platform is HP-UX 11.31 Itanium.

I have code similar to the code below, where ProcessId has the value of a process that is running on the system. I can run ps -ef|grep to verify that the process is in fact running. When I use the C 'kill' function to send a SIGNULL signal to the process to check the status, it always returns a status of -1. I am including at the top of the module. Why is this process showing up as having a status of -1 when ps -ef shows that the process is running?

int ProcessStatus = -1;

ProcessStatus = kill(ProcessId, 0);


Here are the processes shown by ps -ef|grep drm:

marcs 27052 1349 0 11:17:02 ? 0:00 /bin/sh /home/cacsg/mich2/exec/s
tart_drm marcs /home/cacsg/mich2
marcs 27079 1349 0 11:17:05 ? 0:00 /bin/sh /home/cacsg/mich2/exec/s
tart_drm marcs /home/cacsg/mich2
marcs 27047 1349 0 11:17:01 ? 0:00 /bin/sh /home/cacsg/mich2/exec/s
tart_drm marcs /home/cacsg/mich2
marcs 27062 27061 9 11:17:04 ?
marcs 27061 1349 0 11:17:04 ? 0:00 /bin/sh /home/cacsg/mich2/exec/s
tart_drm marcs /home/cacsg/mich2
marcs 27048 27047 0 11:17:01 ?
2 REPLIES 2
Matti_Kurkela
Honored Contributor
Solution

Re: Problem with kill signal in C code

Please check the value of the variable "errno" after calling the "kill" function. It is the standard variable used by many system functions to further describe the causes of error conditions.

The possible errno values after calling kill() are listed in the kill(2) man page (i.e. see "man 2 kill", look for heading "ERRORS").

I guess you might be getting EPERM, if you're trying to kill a process running as a different user. But you could use that as a confirmation the process exists too: if the process wasn't there, you would be getting ESRCH instead.

> Here are the processes shown by ps -ef|grep drm:

As you didn't tell what was the ProcessId you used nor what username you're using for running your program, this information alone is useless for solving the problem.

MK
MK
Curtis Deese
Frequent Advisor

Re: Problem with kill signal in C code

I ran the following command line command and here's what I got. I found the user of one process is mich2 and the user of the process it is trying to kill -0 is marcs.


d1marcs:/home/cacsg/mich2/source/drm>
kill -0 29844
kill: 29844: Permission denied.
d1marcs:/home/cacsg/mich2/source/drm>