How do I find out if a program is running in "C" (this is linux)
In bash I can find out if a program is running and do stuff if it is running or not running
the code in bash
Code:
if [ `pstree | grep -o "progname" | head -n 1` = "progname" ]; then
echo "program is running"
else
echo "program is not running"
fi
How do I do the same thing in "C"
Thanks
:)
Re: How do I find out if a program is running in "C" (this is linux)
I would do it the same way as pstree does it. See http://www.thp.uni-duisburg.de/pstree/
Re: How do I find out if a program is running in "C" (this is linux)
you mean something like:
Code:
if (system("pstree | grep -o "progname" | head -n 1") == "progname"); {
/* program is running */
/* do something here if program is running */
} else {
/* program is not running */
/* do something here if program is not running */
}
for some reason I could not get the above code to work.
Re: How do I find out if a program is running in "C" (this is linux)
No I mean that you can use the pstree code.
The code you have should work as well. See this regarding system return codes though http://pubs.opengroup.org/onlinepubs...ns/system.html