Re: mc sets process group differently from shell; forgets to close fd# 3

On Sat, 21 Apr 2007, Denis Vlasenko wrote:

On Friday 20 April 2007 23:00, Pavel Tsekov wrote:
Small one: child process is not given its own porcess group when run
under mc, while under sh it is. It means that if child will create its

Yes - because, you have a shell which supports job control.

own process group by itself and then die, under shell it works but
under mc mc will auto-background itself on child's death,
because tty's pgrp will not match mc's. Nasty.

I am confused a bit by the statement above. The foreground process
group (tty's pgrp) is controlled by the process which has the
controlling terminal - the shell itself.


Neither the child nor MC
can manipulate the foreground process group.

Yes it can. I spent entire day doing exactly this while I was fixing
a shell from busybox project. It works.

Please, explain in
details what you mean. If can provides a simple testcase to reproduce
the problem I'd be happy to investigate.

Simple: start bash from mc, and kill it so that it (bash) have no chance
to restore tty's pgrp:

# mc
# bash
bash-3.2# kill -KILL $$
[1]+  Stopped                 mc
# _

See? mc is backgrounded!

Yes. My bad - I was under the impression that only the controlling process
can call tcsetpgrp(). I red its specification again several times to make sure I understand it correctly.

This is how it should work (and in fact works when parent is a shell, not mc):

# bash
bash-3.2# kill -KILL $$
Killed <=========== parent shell reports exit status of child
# _

Parent shell has recovered (did not end up backgrounded), because it brought
itself to foreground (did tcsetpgrp(ctty_fd, parent_pid)) after child exited.

Yes. Because it's up to the shell to do job control. I am not quite
sure that MC is supposed to do job control on its own. The example
that you give is not a common case - most programs won't put other
programs in the background for no reason.

I made a simple testcase with VIM - i did as you suggested above i.e.
run a shall and kill it. It behaves the same way as MC does. Why should
we be different ? This is the way it is supposed to be working after

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]