我正在移植一些bash腳本以在busybox上運行。他們使用disown
,這在ash中不被支持,在殺死某些進程以防止來自該進程的消息出現在stdout/stderr中。我想保留這個功能。這意味着關閉stdout/sterr還是在運行後重定向到/dev/null
。如何在沒有`disown`或gdb的情況下關閉進程的stdout和stderr?
它是如何完成的?
我正在移植一些bash腳本以在busybox上運行。他們使用disown
,這在ash中不被支持,在殺死某些進程以防止來自該進程的消息出現在stdout/stderr中。我想保留這個功能。這意味着關閉stdout/sterr還是在運行後重定向到/dev/null
。如何在沒有`disown`或gdb的情況下關閉進程的stdout和stderr?
它是如何完成的?
一旦進程從該進程外運行,您就不能修改文件描述符的重定向。這意味着您在shell創建進程時必須執行重定向。無論是重定向到文件還是關閉Ignacio這樣的文件夾都取決於您。
我不確定爲什麼你認爲bash的disown內置對文件描述符有任何影響。這裏是什麼bash手冊說:
disown [-ar] [-h] [jobspec ...] Without options, each jobspec is removed from the table of active jobs. If jobspec is not present, and neither -a nor -r is supplied, the shell's notion of the current job is used. If the -h option is given, each jobspec is not removed from the ta- ble, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a job- spec does not specify a valid job.
但也許我對你想達到什麼的理解是不完整的。
這個誤解來自我正在移植的腳本。 http://devresources.linuxfoundation.org/dev/hotplug/ 他們有一個殺死一個pid的函數,但是在這之前調用disned。它具有不會將'處理:殺死'打印到終端的副作用。 Busybox ash沒有被拒絕,所以我正在尋找類似的東西。原來重定向kill的輸出完成了這項工作。 – Derrick
exec [n]>&-
將關閉FD [n]
。
你知道'nohup cmd&',會有幫助嗎?祝你好運。 – shellter
感謝您的評論。嗯,這沒有幫助。 – Derrick
對不起,但重新閱讀您的文章,我仍然不清楚您要實現的目標。你可以編輯你的帖子,包括psuedocode,期望的輸入(如果適用)和預期的輸出順序。這組腳本是作爲守護程序還是從crontab運行?祝你好運。 – shellter