0

Bash man lists under set subsection the option -m described so:

Monitor mode. Job control is enabled. This option is on by default for interactive shells on systems that support it (see JOB CONTROL above). Background processes run in a separate process group and a line containing their exit status is printed upon their completion.

(To find it on the linked page, search for 'monitor mode', there's only one hit.)

The question is whether this mode can be effectively turned off during a bash session, how, and with what expected results? I've been trying to experiment, but so far fruitlessly.

I know the command set +m, but what is it supposed to cause? Turning off the job control? Silencing the job completion and termination messages?

1

2 Answers 2

6

set +m does disable monitor mode (also known as job control), but that doesn't have much effect, and most of those aren't useful effects. When a background job is started with monitor mode turned off, the job isn't eligible for fg and bg, and the shell doesn't execute print a message or execute SIGCLD traps when the job dies, is stopped or is resumed.

The main useful difference is that monitor mode causes pipelines to run in their own process group. This is a useful consideration when you want to kill a whole process group. If monitor mode is disabled then killing the shell's process group kills its subprocesses as well, if it's enabled then each pipeline is its own group and can be group-killed independently..

bash-4.3$ set -m
bash-4.3$ sleep 1111 &
[1] 17526
bash-4.3$ set +m
bash-4.3$ sleep 2222 &
[2] 17527
bash-4.3$ ps -o pid,ppid,pgid,sid,cmd 17526 17527
  PID  PPID  PGID   SID CMD
17526 17525 17526  7773 sleep 1111
17527 17525 17525  7773 sleep 2222
2

To disable monitor mode, just run:

set +m

For example:

$ echo $SHELLOPTS
braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
$ set +m
$ echo $SHELLOPTS
braceexpand:emacs:hashall:histexpand:history:interactive-comments
1
  • Thanks and sorry. I should have posted what I've tried and more details. I know set +m, but it seems to bring no change in the behaviour, apart from the $SHELLOPTS contents. Namely, the jobs control, ie. jobs - I assume - still works. So what's the real effect?
    – user147505
    Nov 23, 2016 at 14:19

You must log in to answer this question.