[Haskell-cafe] Running a "sub-process" which dies with the main program

Donn Cave donn at avvanta.com
Thu Jun 18 17:47:25 EDT 2009


Quoth Deniz Dogan <deniz.a.m.dogan at gmail.com>,

> I have a small program which spawns a subprocess. However, when I hit
> C-c, the subprocess won't die, instead it will just keep running until
> it's done or until I kill it. I've looked around in System.Process for
> something suitable for my needs, but I can't seem to find it. Any
> ideas?

What you want, is the normal behavior for Berkeley/UNIX/POSIX ttys:
signals generated by the (pseudo)tty handler from control characters
are delivered to all processes in the foreground process group, which
is a hereditary distinction where you have to actively opt out.

Berkeley job control shells (bash, ksh et al.) reset process group on
commands issuing from the terminal, so the foreground process group is
whatever you invoked, and any subprocesses thereof (barring further
process group resets), and that's what will abort if you press ctrl-C.

If it isn't working that way, possibilities might include:

 - not a POSIX operating system

 - subprocess set its process group and is no longer in the terminal
   foreground process group.

 - a signal handler caught/ignored ctrl-C.

Along with process group stuff in System.Process, if both processes are
Haskell you might look at System.Posix.Terminal getTerminalProcessGroupID,
as a way to directly check the second item above (and I suppose indirectly
the first.)  Unfortunately, none of these explanations come with any
suggested remedy - they're just three ways to say "platform [OS or Haskell 
implementation] doesn't support POSIX ttys".

	Donn



More information about the Haskell-Cafe mailing list