Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!maverick.ksu.ksu.edu!ux1.cso.uiuc.edu!news.cs.indiana.edu!samsung!uunet!convex!news From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.questions Subject: Re: Program name from PID? Message-ID: <1991Feb15.051742.7799@convex.com> Date: 15 Feb 91 05:17:42 GMT References: <59@rscsys.UUCP> Sender: news@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Distribution: usa Organization: CONVEX Software Development, Richardson, TX Lines: 22 Nntp-Posting-Host: pixel.convex.com From the keyboard of bob@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@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