Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cunixf.cc.columbia.edu!sol.ctr.columbia.edu!bronze!news.cs.indiana.edu!samsung!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: Program name from PID? Message-ID: <6109@auspex.auspex.com> Date: 17 Feb 91 23:26:54 GMT References: <59@rscsys.UUCP> Distribution: usa Organization: Auspex Systems, Santa Clara Lines: 33 >Given a process id, how can I find out the name of the process it belongs >to? Others have noted various ways of fetching various information about a process that could be considered the "name" of the process. The two bits of information that could be considered the process's "name" are: 1) the "u_comm" field from the process's U area. This is the first N characters of the last component of the pathname of the last program "exec"ed by the process (or the last "#!" script - many systems arrange that it be the name of the script, rather than the name of the interpreter on the "#!" line). 2) something extracted from the "command line" for the process. On some systems, this may appear in the U area as a character string; on other systems, it may have to be extracted from the top of the process's stack. In the former case, the first token in that string will be whatever was passed as "argv[0]" when the last "exec" was done; by convention, this is usually either the full pathname of the last program (or #! script) "exec"ed by the process), but it need not be - see my followup to the message here with the subject line "Unknown process on sparc". In the latter case, the above applies; in addition, the process can overwrite that string with whatever it wants to, and some programs, in fact, do so. In other words, make sure you know what you want to do with that "name", and make sure that the "name" you're fetching provides the information you need....