Thread: A few process questions...

  1. #1
    Registered User DavidG's Avatar
    Join Date
    Mar 2006
    Location
    England
    Posts
    13

    A few process questions...

    Just a couple of things I need to know about processes:

    1 - is there a way to test if a particular process is still running?
    (assuming you've got its PID, of course)

    2 - is there a way to make a process wait until all of its child processes have finished running?

    3 - is there a way to kill all child processes (of the current process) at once?

    Thanks in advance (even if all three answers turn out to be "no", which would be less than helpful...)

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    277
    Quote Originally Posted by DavidG
    Just a couple of things I need to know about processes:

    1 - is there a way to test if a particular process is still running?
    (assuming you've got its PID, of course)

    2 - is there a way to make a process wait until all of its child processes have finished running?

    3 - is there a way to kill all child processes (of the current process) at once?

    Thanks in advance (even if all three answers turn out to be "no", which would be less than helpful...)
    This might help http://www.cs.cf.ac.uk/Dave/C/node22.html
    About question 3 answer is no, you will have an orphaned process running
    This also may help http://www.cs.sfu.ca/CC/CSILUnix/runaways.html
    Last edited by Maragato; 05-10-2006 at 08:18 AM.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It might help if we knew which OS you were talking about.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Question 3 is possible. Just keep track of child PIDs as they're created and when you want to kill the child processes you can call kill(pid, SIGKILL) (or some other appropriate signal).

    This is of course assuming your environment has the kill() function. Like Salem pointed out, this is implementation-specific.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User DavidG's Avatar
    Join Date
    Mar 2006
    Location
    England
    Posts
    13
    It's Unix. (Cygwin, really, but since that's designed to act like Unix...)

    Thanks for the help with question 3. I'm keeping all the child PIDs in a linked list, so that'd be relatively easy. (The linked list is why I asked question 1, in fact.)

    ---EDIT---

    OK, I've found a way to handle question 1 with the kill() system call - that just leaves question 2.
    Last edited by DavidG; 05-11-2006 at 07:37 AM.

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    For question 2, use the waitpid() function for each PID in your child PID list.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Understanding fork()
    By NuNn in forum C Programming
    Replies: 8
    Last Post: 02-27-2009, 12:09 PM
  2. how to get process info ( to extract process thread id )
    By umen242 in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2009, 01:08 PM
  3. One process with two console windows
    By siavoshkc in forum Windows Programming
    Replies: 8
    Last Post: 01-30-2009, 04:13 PM
  4. process ring
    By gregulator in forum C++ Programming
    Replies: 0
    Last Post: 02-28-2005, 08:21 PM
  5. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-28-2005, 12:59 AM