how to determine if a program is running?
I know the program's name and path.
how to implement it with c code? Regards |
what are you talking about?
need more info to help. if you want to see any active tasks you can use. Code:
ps -al i think this might be what you are looking for, but i'm not sure. implement in c code? you can run a system command to execute the ps command in the shell maybe. are you writing a program that will be implimenting another program? |
system("ps ax | grep UR-APP-NAME > /tmp/1337");
fopen("/tmp/1337", r); then read out the file; if its empty u know program is not running but this is a very ugly implementation |
xviddivxoggmp3,freeka, thank you.
I'm a new to Linux, is there any C fuctions that can do this? |
not that i know of, but would be interesting. i think there exist a function in the kernel layer, dont know how to access and use it, i would be glad if someone can say somethin about it :>
however, i needed it in the past too, and wrote out of this implementation a crappy function by myself(but worked for me) which looked like this Code:
/* |
When it's not done in C entirely anyway (i.e. using system() or popen(),..), it's pobably easier/faster to use the "pidof" shell utility:
Code:
bash$ pidof init |
Although it will make your C code more complicated, you do not need to call a shell command from C to gather information about processes, you can instead directly browse the /proc filesystem.
|
Quote:
But if I'm not root, I have a lot of "permission denied revolving symlink"-like errors (through perror()). A regular user however can read /proc/<pid>/cmdline which contains (more or less) the name of the executable also. But this isn't accurate as it does not allways have the full path. Worse yet, programs can change argv[0] (I guess /proc/<pid>/cmdline == argv[0] ). And some programs actually do this. E.g. I've read somewhere sendmail does this. Is it at all possible, for a regular user to see (accurately) if a given executable file is running? |
Did you look at /proc/<pid>/stat ?
The filename of the program is the second field between ( and ) |
I don't konw how to do it gracefully.
There must be some APIs, but I don't know. Looking forward to your help. Here are my code...... Code:
/************************************************************************/ |
I forgot to say, I don't know how to get a process' full path.
And my fuction above is somewhat ugly... Hope for your help Regards |
All times are GMT -5. The time now is 10:31 PM. |