Results 1 to 4 of 4
Hi All,
I have to find the executable file path by using the PID (process ID).
User will input some PID and required output is corresponding executable file path.
For ...
- 04-24-2009 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 49
find executable path
Hi All,
I have to find the executable file path by using the PID (process ID).
User will input some PID and required output is corresponding executable file path.
For this i have to write a C program using system call. Anyone help me.
- 04-24-2009 #2
I can't understand your requirement..note : every process creates a directory under /proc...if you know the PID you can get the Envorimental values and others process related info from there,check those files ....
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 04-27-2009 #3
Try this
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
char *getpath(int pid)
{
FILE *fp;
char command[256];
char output[64];
char reply[32];
strcpy(reply, "");
sprintf(output, "/tmp/.path.%d", pid);
sprintf(command, "/usr/proc/bin/pmap %d | nawk '\n{\nif(substr($3,3,1)==\"x\") {\nprint $4\nexit(0);\n}\n}\n'>%s",
pid, output);
system(command);
if((fp=fopen(output, "r"))!=NULL)
{
fgets(reply, 32, fp);
fclose(fp);
unlink(output);
}
return(reply);
}
main(int argc, char **argv)
{
printf("%s", getpath(atoi(argv[1])));
}
- 04-28-2009 #4
I hope you'll forgive me if I think that spawning off awk from a C program is not the best way to go about this.
First of all, is this a homework assignment? It does sort of sound like one. Homework assignments are not allowed on this forum.
Assuming that it is not, Lakshmipathi is correct. Every PID has a directory under /proc. Each of these directories has a lot of information about the particular process. One file in that directory is called cmdline, and I suspect it will help you. Check "man proc" for more information.DISTRO=Arch
Registered Linux User #388732


Reply With Quote