Operating System - HP-UX
1753907 Members
9020 Online
108810 Solutions
New Discussion юеВ

"kill -0" to a process owned by a different user.

 
skt_skt
Honored Contributor

"kill -0" to a process owned by a different user.

HP-UX 11.11/ PARISC

I have a process [pid] owned by user AAA and I want to access the pid [kill -0 pid ] from another user BBB.

I get a permission denied error when i tried it. Is there a way to get this "process access check" get working by any method??.

I have a custom code which does this stuff and need to get a exit code zero for the program to go further.
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor

Re: "kill -0" to a process owned by a different user.

Hi:

Instead of testing the pid with 'kill -0' I would suggest a simple interrogation with 'ps':

For example, by process name:

# PIDS=$(UNIX95= ps -C myprocess -opid=)

# [ -z "${PIDS}" ] && echo "dead" || echo "alive"

Regards!

...JRF...
Horia Chirculescu
Honored Contributor

Re: "kill -0" to a process owned by a different user.

Hello,

#-------------------
PID=other_user_pid_no
test=`ps -e | awk '{print $1}' |grep $PID`

if [ "$test" != "$PID" ] ; then echo "We can not test the validity of $PID.";
exit 1;
else
# whatever...
exit 0;
fi
#-------------------

Best regards,
Horia.

Best regards from Romania,
Horia.
James R. Ferguson
Acclaimed Contributor

Re: "kill -0" to a process owned by a different user.

HI (again):

Too, if you know the pid and don't want to fiddle with the process name, you could do:

# PID=$(UNIX95= ps -p 1234 -opid=)

# [ -z "${PID}" ] && echo "dead" || echo "alive"

Obviously, substitute the actual pid in question for the "1234" value.

Once again, we leverage the UNIX95 behavior of 'ps' to create a custom output of *only* the pid *if* the pid can in fact be found. The '-opid=' says that the output should be the pid and that the normal 'ps' header line should be suppressed.

Regards!

...JRF...
skt_skt
Honored Contributor

Re: "kill -0" to a process owned by a different user.

I am not lloking for a code modify, rather any other possible changes we could get the same thing working.some unix tricks such as setuid, sticky bit , acl ...
James R. Ferguson
Acclaimed Contributor

Re: "kill -0" to a process owned by a different user.

Hi (again):

> I am not lloking for a code modify, rather any other possible changes we could get the same thing working.some unix tricks such as setuid, sticky bit , acl

Then create a 'setuid' executable that runs with an effective uid of zero.

Regards!

...JRF...
Matti_Kurkela
Honored Contributor

Re: "kill -0" to a process owned by a different user.

kill -0 tests if you may send a signal to the target process. If you are not the owner of the process or root, the answer will always be "no".

If you have the PID and just want to know if the process exists or not, you should use the ps command with the -p option. If you want only the information about the existence of the process, throw the ps output away and use only the result code returned by the ps command.

Example:

#!/bin/sh
pid=1 # or whatever

if ps -p $pid >/dev/null; then
echo "process $pid exists"
else
echo "process $pid does not exist"
fi

MK
MK
Horia Chirculescu
Honored Contributor

Re: "kill -0" to a process owned by a different user.

>Then create a 'setuid' executable that runs with an effective uid of zero.

... or with the uid corresponding to user BBB.

Horia.
Best regards from Romania,
Horia.