if i'm in control of the other program, i'm thinking that the best way is to create a pid file using getpid(). the other prog can then read the file to get the pid.
if i'm not then maybe accessing proc or using ps - a bit clumsy though!
You could read the proc directory using opendir(), readdir() and closedir() functions looking for any subdirectory directory that is purely numeric in name then examine the contents of the stat file in each such dub-directory. This will have the binary name within a pair of brackets.
When this name matches the target application you know that the directory name containing this file is the pid of the application.
newmangj's is a good way, not very easy to do.
i propose the old way; scann the output of ps.
#define MYPS "/bin/ps -efopid,comm" /* on a solaris-os */
FILE *ps = popen(MYPS,"r"
while(fgets(buff,MAXBUFF,ps)){
if 'name' not in 'buff' continue;
pid = atoi(buff);
...
...
}
pclose(ps);
it my be old-fashioned, but it works ans is portable.
you only have to change the ps statement.
for the if use a string function. ------------ jamisar
Einfachheit ist das Resultat der Reife. (Friedrich Schiller)
Simplicity is the fruit of maturity.
Not very similar but a related query. How do I copy a file
from one location to another using pure ANSI C calls ? Is there a portable, atomic function in ansi c libraries to do this ?
Thanks
Anand Pillai ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mail me at abpillai@excite.com if you want additional help. I dont promise that I can solve your problem, but I will try my best.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.