[ucc] process trees/groups issue

Bernard Blackham bernard at blackham.com.au
Sun Nov 6 11:00:45 WST 2005


Free drink/beer on me to anybody who can figure this out.
And apologies to those on #ucc who saw this last night...

I have a process that is run from the shell. It spawns off another
process as its child. The process tree at this point looks like
  sh
   \_ task1
      \_ task2

I'd like to kill off task1 and get the process tree to look like
  sh
   \_ task2

Well, specifically what I'd practically like to do is to have task1
die, and still have the shell wait for task2 to terminate before
regaining control of the terminal. How the process tree looks really
is irrelevant.

The problem is that the shell doesn't know about task2 and so will
never wait for it. It'll return as soon as task1 exits. When task1
does exit, task2 is reparented to init.

I've tried magic with process groups, tty process groups, the
CLONE_PARENT flag, and more, to no avail. Here's boilerplate code of
task1 I'm hoping to fill in the blanks with (task2 is bash):

---
#include <unistd.h>

int main() {
	if (!fork()) { /* excuse the lack of error handling */
		execl("/bin/bash", "bash", NULL);
	}
	return 0;
}
---

Any ideas?

Thanks,

Bernard.

-- 
 Bernard Blackham <bernard at blackham dot com dot au>



More information about the ucc mailing list