Program name from PID?

Tom Christiansen tchrist at convex.COM
Fri Feb 15 16:17:42 AEST 1991


>From the keyboard of bob at rscsys.UUCP (Bob Celmer):
:Given a process id, how can I find out the name of the process it belongs
:to?  Unfortunately, grepping ps output is not a viable option.  The specific
:system is Xenix 2.3.2 running on 386 based machines.  Also, how might this
:problem be solved on other Unix platforms?

I don't know what's wrong with grepping ps output.  If for some reason, 
I just weren't allowed to do this, I would do something like this

 printf("pid %d is command %s\n", pid, getprocstruct(pid)->p_uaddr->u_comm);
		
Writing getprocstruct() is left as an excersize to the reader. Actually,
you won't be able to directdly deref the pointer in user space, but 
you get the idea.

Perhaps you should reconsider ps. :-)

--tom
--
Tom Christiansen		tchrist at convex.com	convex!tchrist
"With a kernel dive, all things are possible, but it sure makes it hard
 to look at yourself in the mirror the next morning."  -me



More information about the Comp.unix.questions mailing list