-
October 11th, 2012, 11:50 PM
#1
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
Last edited by n_techo; October 12th, 2012 at 01:31 AM.
-
October 12th, 2012, 12:27 AM
#2
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/
-
October 12th, 2012, 01:25 AM
#3
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.
Last edited by n_techo; October 12th, 2012 at 01:31 AM.
-
October 12th, 2012, 03:06 AM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|