Thread View: comp.unix.internals
3 messages
3 total messages
Started by Brian Ceccarelli 602/621-9615
Thu, 21 Jan 1993 22:06
System Call which Returns Executing Program Name?
Author: Brian Ceccarelli 602/621-9615
Date: Thu, 21 Jan 1993 22:06
Date: Thu, 21 Jan 1993 22:06
16 lines
838 bytes
838 bytes
This should be an easy one for your UNIX gurus out there. 8-) Is there a system function I can call which returns the name of the executing program? I need to place such a function in some lower object library. Information in the argv of main(argc, argv) is not available at this level. Thanks! Brian Ceccarelli ---------------- brian@gamma1.lpl.arizona.edu
Re: System Call which Returns Executing Program Name?
Author: Brian Ceccarelli 602/621-9615
Date: Fri, 22 Jan 1993 16:02
Date: Fri, 22 Jan 1993 16:02
11 lines
724 bytes
724 bytes
I don't care what those people say about you guys! You guys are GREAT! Thanks to all of you for your help! Sincerely, Brian Ceccarelli ---------------- brian@gamma1.lpl.arizona.edu
Re: System Call which Returns Executing Program Name?
Author: raj
Date: Fri, 22 Jan 1993 16:48
Date: Fri, 22 Jan 1993 16:48
56 lines
2221 bytes
2221 bytes
In article <1993Jan21.220641.5858@organpipe.uug.arizona.edu>, brian@lpl.arizona.edu (Brian Ceccarelli 602/621-9615) writes:
|> This should be an easy one for your UNIX gurus out there. 8-)
|>
|> Is there a system function I can call which returns the
|> name of the executing program?
|>
|>
|> I need to place such a function in some lower object library.
|> Information in the argv of main(argc, argv) is not available
|> at this level.
|>
|> Thanks!
|>
|> Brian Ceccarelli
|> ----------------
|> brian@gamma1.lpl.arizona.edu
|>
One way of getting the name of the current (or any) executing program
is to use the proc filesystem on SVR4. The following C program
will do the needful.
/*
* Gets the name of the current command/process - raj
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/procfs.h>
main()
{
int procfd; /* fd for /proc/xxxxx */
char pname[20];
int pid = getpid();
struct prpsinfo info; /* process ps info */
printf ("my pid = %d\n",pid); /* use the pid of process */
sprintf(pname, "/proc/0%d",pid);
if ((procfd = open(pname, O_RDONLY)) == -1) {
printf("could not open /proc/%s\n",pname);
exit(1);
}
/* read the info from /proc */
if (ioctl(procfd, PIOCPSINFO, (char*)&info) == -1) {
printf("ioctl on open /proc/%s failed\n",pname);
close (procfd);
exit(2);
}
close(procfd);
printf("my command name = %s\n",info.pr_fname);
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads