#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    3
    Rep Power
    0

    process status in linux


    I was wondering if there was any way to dynamically get all of the process info from linux in C++. U know there is an API in windows. I really dont want to pipe the info and parse from
    "ps -etc,etc".

    This would be to retreive info given a known pid. I forked some child processes and want to periodically check their status. ( ie crashed or running )

    I would appreciate some backup :)
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    when you fork a process it shoud be stored like this:
    Code:
    if( (cpid = (fork())) == 0)
    {
       //blablah child
        //child's copy of cpid is  0 and can get its own pid 
       //with some function i 4got maybe getpid()
       //and getppid() for the parents pid
    }
    else if(cpid < 0)
     //bla error
    //parent has copy of pid with child's pid
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    3
    Rep Power
    0
    I had already forked the process and retreived the pid, but I need to know how I can make sure they are all still running, or if they crashed, so I can restart them. Basically a status update AFTER forking them. I'm having no problem running them.
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    man waitpid

    HTH :)
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    3
    Rep Power
    0
    I could use waitpid, but I wanted to be able to save pids in a DB so when I restart the prog, it will check all those pids and start the ones that had crashed, or not start any if they were still running... any ideas? If not thnx for your help. I have more than enough info to use waitpid at runtime :)

IMN logo majestic logo threadwatch logo seochat tools logo