bash 中进程替换中的命令何时开始和完成运行?例如
分别什么时候
command1
开始command2 >(command1)
和结束运行?分别什么时候
command3
开始command4 <(command3)
和结束运行?
FIFO 中的命令何时开始和结束运行?例如
- 分别什么时候
prog2
开始mkfifo fifo1; prog2 < fifo1 &; prog1 > fifo1;
和结束运行? - 分别什么时候
prog3
开始mkfifo fifo2; prog3 > fifo12 &; prog2 < fifo2;
和结束运行?
谢谢。
答案1
实验上,在 bash 中:
$ strace -tttfe execve bash -c 'sleep 5 <(sleep 6)'
1522025733.188859 execve("/bin/bash", ["bash", "-c", "sleep 5 <(sleep 6)"], [/* 41 vars */]) = 0
strace: Process 24248 attached
[pid 24247] 1522025733.215188 execve("/bin/sleep", ["sleep", "5", "/dev/fd/63"], [/* 41 vars */]) = 0
strace: Process 24249 attached
[pid 24249] 1522025733.218331 execve("/bin/sleep", ["sleep", "6"], [/* 41 vars */]) = 0
sleep: invalid time interval ‘/dev/fd/63’
Try 'sleep --help' for more information.
[pid 24247] 1522025733.227459 +++ exited with 1 +++
[pid 24249] 1522025739.230933 +++ exited with 0 +++
1522025739.232270 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=24249, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
1522025739.233169 +++ exited with 0 +++
$ strace -tttfe execve bash -c 'sleep 5 >(sleep 6)'
1522025752.162876 execve("/bin/bash", ["bash", "-c", "sleep 5 >(sleep 6)"], [/* 41 vars */]) = 0
strace: Process 24253 attached
[pid 24252] 1522025752.188413 execve("/bin/sleep", ["sleep", "5", "/dev/fd/63"], [/* 41 vars */]) = 0
strace: Process 24254 attached
[pid 24254] 1522025752.191032 execve("/bin/sleep", ["sleep", "6"], [/* 41 vars */]) = 0
sleep: invalid time interval ‘/dev/fd/63’
Try 'sleep --help' for more information.
[pid 24252] 1522025752.197213 +++ exited with 1 +++
[pid 24254] 1522025758.197114 +++ exited with 0 +++
1522025758.197959 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=24254, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
1522025758.198820 +++ exited with 0 +++
command1
并分别在和command3
之后开始。command2
command4
只要满足退出或被杀死的条件,他们就会退出。
makefifo fifo1; prog2 < fifo1 &; prog1 > fifo1;
和makefifo fifo2; prog3 > fifo12 &; prog2 < fifo2;
是语法错误,至少在 bash 中是这样。即使不是,我也没有在重定向中看到任何会导致与没有重定向时不同的执行顺序的内容。