A few process questions...

This is a discussion on A few process questions... within the C Programming forums, part of the General Programming Boards category; Just a couple of things I need to know about processes: 1 - is there a way to test if ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,443
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,162
    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,162
    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, 11:09 AM
  2. how to get process info ( to extract process thread id )
    By umen242 in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2009, 12:08 PM
  3. One process with two console windows
    By siavoshkc in forum Windows Programming
    Replies: 8
    Last Post: 01-30-2009, 03:13 PM
  4. process ring
    By gregulator in forum C++ Programming
    Replies: 0
    Last Post: 02-28-2005, 07:21 PM
  5. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-27-2005, 11:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21