作者shihyuyao (shihyuyao)
看板LinuxDev
标题[问题] shell background 差异
时间Wed Oct 21 20:24:15 2015
https://gist.github.com/anonymous/f44a39855f022c280ecd
使用 sh test1.sh 後
ps aux | grep 'my_fork' // 找不到 my_fork 父跟子行程
但是改成 sh test2.sh &
ps 可以看到my_fork 父子行程
好奇为什麽把 & 写在 test1.sh 里面为什麽无法看到父跟子行程?
因为我my_fork 程式里面有 getchar(); 卡住
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 112.104.88.20
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/LinuxDev/M.1445430260.A.07B.html
1F:推 yvb: 因为 shell script 中的 background commands, 10/21 22:42
2F:→ yvb: 其 standard input 会被指向 /dev/null . 10/21 22:43
3F:→ shihyuyao: standard input 会被指向 /dev/null会影响 my_fork程式 10/21 23:35
4F:→ shihyuyao: fork 行程出来? 10/21 23:35
5F:→ leolarrel: 不是,yvb的意思是你的重点在於 getchar(); ..... 10/22 14:30
6F:→ leolarrel: 如果你想要让行程暂停,好让你可以用ps aux验证,那你可 10/22 14:32
7F:→ leolarrel: 以用sleep 或做一些无穷回圈的事情 10/22 14:33
8F:推 yvb: 意思就是, stdin 被指向 /dev/null 时, getchar() 不会卡住. 10/22 19:20
9F:→ yvb: 同样道理, 试试看 sh test2.sh < /dev/null 10/22 19:23