Find the answer to your Linux question:
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.
  1. #1
    Just 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

  2. #2
    Just Joined!
    Join Date
    Mar 2009
    Posts
    1

    Thumbs up

    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

  3. #3
    Just Joined! vlnrajesh's Avatar
    Join Date
    Mar 2007
    Posts
    11
    Thanks lakshika,

    It is working for me and i am able to get he PID for that

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •