Results 1 to 3 of 3
hi
i am writing a simple application which start 2 threads in it.
i am writing one more application that will monitor this application if it is alive or killed. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-26-2009 #1Just Joined!
- Join Date
- Jan 2009
- Posts
- 8
process monitor
hi
i am writing a simple application which start 2 threads in it.
i am writing one more application that will monitor this application if it is alive or killed. if killed i need to restart it.
in /proc/<process pid>/ i will get all the information regarding that process.
as i am writing a c program how can i get the process pid so that i can search in /proc. example code will appreciated
- 03-02-2009 #2Just Joined!
- Join Date
- Mar 2009
- Posts
- 1
Hi Maggi,
Please find the below sample code to run unix command & get the result into output string
-----------------------------------------------------------------------------------------------------------
int run_unix_command(const char *command,char *output)
{
FILE *file;
char line[512];
int ret = -1;
file = popen(command , "r");
if (file != NULL)
{
if (fgets(line , sizeof ( line ) , file) == NULL)
{
ret = -1
}
else
{
strcpy(output,line);
ret = 1;
}
pclose(file);
}
return ret;
}
----------------------------------------------------------------------------------------------
Lakshika



“A community site where you can try Open Source software for free. right in your browser.”
www.click2try.com
- 03-02-2009 #3
Thanks lakshika,
It is working for me and i am able to get he PID for that


Reply With Quote
