명령을 분기하고 최소한의 Busybox 셸에서 비동기적으로 실행하는 데 이 특수 장치가 필요한 이유가 궁금합니다.
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
/ #
답변1
~에서구현하다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.
*/
"입력이 /dev/null로 리디렉션됨"에 유의하세요. 서브셸의 표준 입력이 리디렉션되기 때문에 /dev/null
(작업 제어가 꺼져 있고 액세스 /dev/tty
할 수 없기 때문에 리디렉션될 예정임) 장치 파일에 액세스할 수 없으면 오류가 발생합니다.