0

I'm curious why this special device is needed to fork the command and run it asynchronously in the minimal Busybox shell.

BusyBox v1.30.1 (Debian 1:1.30.1-4) built-in shell (ash)
Enter 'help' for a list of built-in commands.

/bin/sh: can't access tty; job control turned off
/ #
/ # echo Hello && sleep 2s && echo World &
/bin/sh: / # can't open '/dev/null': No such file or directory

/ #
/ # mknod /dev/null c 1 3 && chmod 666 /dev/null
/ # echo Hello && sleep 2s && echo World &
/ # Hello
World

/ #
2
  • /dev/null is the location you direct output to if you don’t want to see it. Can you explain what you are trying to do
    – PonJar
    Commented Oct 4, 2022 at 13:46
  • @PonJar They are using the busybox tools on a system with no or few devices in /dev.
    – Kusalananda
    Commented Oct 4, 2022 at 13:47

1 Answer 1

2

From the implementation of the shell in busybox:

/*
 * Fork off a subshell.  If we are doing job control, give the subshell its
 * own process group.  Jp is a job structure that the job is to be added to.
 * N is the command that will be evaluated by the child.  Both jp and n may
 * be NULL.  The mode parameter can be one of the following:
 *      FORK_FG - Fork off a foreground process.
 *      FORK_BG - Fork off a background process.
 *      FORK_NOJOB - Like FORK_FG, but don't give the process its own
 *                   process group even if job control is on.
 *
 * When job control is turned off, background processes have their standard
 * input redirected to /dev/null (except for the second and later processes
 * in a pipeline).
 *
 * Called with interrupts off.
 */

Note "input redirected to /dev/null". Since subshells have their standard input redirected from /dev/null (and it will be, since job control is turned off, which it will be because /dev/tty is also not accessible), you'd get an error if that device file is not accessible.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .