1

I don't understood, why I can't run some process ("cat" in this example) in background and later make it foreground:

$ dash
$ f() { cat </dev/stdin > /dev/stdout &  sleep 1; fg ; }
$ sleep 2 | f
dash: 1: fg: job (null) not created under job control
$ set -m 
$ sleep 2 | f
dash: 1: fg: job (null) not created under job control
$ f() { set -m; cat </dev/stdin > /dev/stdout &  sleep 1; fg ; }
$ sleep 2 | f
dash: 5: fg: job (null) not created under job control

Why every time I'm getting error message?

At some time I have no such messages when running function "f" without pipe:

$ set +m
$ f
cat 0</dev/stdin 1>/dev/stdout
^C
$ set -m
$ f
cat 0</dev/stdin 1>/dev/stdout
^C
Kirill Frolov
  • 401
  • 4
  • 10
  • Looks like job control is enabled in shell only if this shell process is the process group leader. Another example, which gives strange result: $ sleep 2 | sh -c "set -m; cat /dev/stdout & sleep 1; fg" cat 0/dev/stdout sh: 1: Cannot set tty process group (No such process) – Kirill Frolov Oct 05 '18 at 18:36
  • 2
    When you run the function in a pipeline, it's run in a subshell, but job control is only available in the main shell. – Barmar Oct 05 '18 at 19:25
  • Is this `dash` or `bash`? – cdarke Oct 05 '18 at 21:38

0 Answers0