Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Process Name?

0 views
Skip to first unread message

Nathan Nesbit

unread,
Mar 24, 1997, 3:00:00 AM3/24/97
to

jb wrote:
> I've been asked to modify a bit of code that uses openlog() and syslog() to
> use and write to log files. We would like to get the name of a given process
> that is running when we write an entry.
>
> I haven't been able to find anything in the few unix programming books I
> have access to. In addition, I've just finished reading Andrew Gierth's faq
> (nice job so far!) and, in 1.8 in particular, is a question similar to mine
> wherein it is suggested that popen(pscmd, "r") be used. So, I suppose I'm
> posting to confirm my (new) assumption: there is no function I can call
> (perhaps with a pid) to get back the name of a process, or is there?

I'm not sure if this is what you want, but the first commandline
parameter (number 0) is the name of the executable that was ran.

Nathan Nesbit

jb

unread,
Mar 25, 1997, 3:00:00 AM3/25/97
to

Hi,

I've been asked to modify a bit of code that uses openlog() and syslog() to
use and write to log files. We would like to get the name of a given process
that is running when we write an entry.

I haven't been able to find anything in the few unix programming books I
have access to. In addition, I've just finished reading Andrew Gierth's faq
(nice job so far!) and, in 1.8 in particular, is a question similar to mine
wherein it is suggested that popen(pscmd, "r") be used. So, I suppose I'm
posting to confirm my (new) assumption: there is no function I can call
(perhaps with a pid) to get back the name of a process, or is there?


thanks,
joe

Andrew Gierth

unread,
Mar 25, 1997, 3:00:00 AM3/25/97
to

>>>>> "jb" == jb <j...@euler.access.digex.net> writes:

jb> Hi,
jb> I've been asked to modify a bit of code that uses openlog() and
jb> syslog() to use and write to log files. We would like to get the
jb> name of a given process that is running when we write an entry.

Do you mean the name of the *current* process?

jb> I haven't been able to find anything in the few unix programming
jb> books I have access to. In addition, I've just finished reading
jb> Andrew Gierth's faq (nice job so far!) and, in 1.8 in particular,
jb> is a question similar to mine wherein it is suggested that
jb> popen(pscmd, "r") be used. So, I suppose I'm posting to confirm
jb> my (new) assumption: there is no function I can call (perhaps
jb> with a pid) to get back the name of a process, or is there?

There's no simple function to get the name of an arbitrary process. But
if it's the current process you're interested in, then the thing usually
done is to capture the value of argv[0] on program entry, and use the
basename of that (i.e. everything after the last '/', if any) as an
identifier. Unfortunately, there is no standard mechanism to get this
information from a library function, if main() didn't conveniently
save it somewhere.

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>

Paul Colclough

unread,
Mar 25, 1997, 3:00:00 AM3/25/97
to

jb (j...@euler.access.digex.net) wrote:

: I've been asked to modify a bit of code that uses openlog() and syslog() to
: use and write to log files. We would like to get the name of a given process


: that is running when we write an entry.

depends on your OS, if your using one that supports the /proc file
system, then you could get the relevent information from there. SunOS has
functions to peek into the process structures but you need to be root to
use them. There is some rather useful code in the faq for this newsgroup.

--
pa...@squiznet.demon.co.uk (U.K) http://www.squiznet.demon.co.uk
pa...@sunsite.unc.edu (U.S) http://sunsite.unc.edu/paulc

Gerry S Hayes

unread,
Mar 26, 1997, 3:00:00 AM3/26/97
to

Nathan Nesbit <Nathan...@byu.edu> writes:
>
> I'm not sure if this is what you want, but the first commandline
> parameter (number 0) is the name of the executable that was ran.

But note that a program can change this; people have been known to
write programs that run nethack but change ARG 0 to "latex thesis"...

Cordially,

Sumner

--
Respond by post or email, but please don't do both; my mailbox is
already quite full.

Vikas Dewan

unread,
Mar 28, 1997, 3:00:00 AM3/28/97
to Paul Colclough

Paul Colclough wrote:
>
> jb (j...@euler.access.digex.net) wrote:
>
> : I've been asked to modify a bit of code that uses openlog() and syslog() to
> : use and write to log files. We would like to get the name of a given process
> : that is running when we write an entry.
>

openlog(process_name_str, LOG_PID | LOG_NDELAY, LOG_DAEMON);

Vikas Dewan

0 new messages