Linux BASH:发送SIGTSTP信号(ctrl+z)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9900970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
BASH: send SIGTSTP signal (ctrl+z)
提问by noobler
I'm rushing against the clock for a programming assignment in which I have to run a number of instances of the same program on the same machine at the same time. Currently, I'm starting the instances one at a time, pressing Ctrl+zto pause them, and then doing 'bg %#' to resume execution in the background.
我正在争分夺秒地进行编程任务,在该任务中我必须同时在同一台机器上运行同一程序的多个实例。目前,我一次启动一个实例,按Ctrl+z暂停它们,然后执行'bg %#' 以在后台恢复执行。
This is extremely tedious and time consuming to do every time I need to test a small change in my application, so I want to write a bash script that will start the multiple instances for me, however I don't know how to do the background switching in a script.
每次我需要在我的应用程序中测试一个小的更改时,这都是非常乏味和耗时的,所以我想编写一个 bash 脚本来为我启动多个实例,但是我不知道如何做后台在脚本中切换。
Can anybody please tell me how I can write a simple script that will start a long standing command, pause it, and resume it in the background?
谁能告诉我如何编写一个简单的脚本来启动一个长期存在的命令,暂停它并在后台恢复它?
Thanks
谢谢
采纳答案by Edward Thomson
Do you want to just startit in the background? For example:
你想在后台启动它吗?例如:
mycommand &
If you want finer grained job control, you can emulate Ctrl-Zand bg
. Control-Zsends SIGTSTP
("tty stop") to the program, which suspends it:
如果您想要更细粒度的作业控制,您可以模拟Ctrl-Z和bg
. Control-Z发送SIGTSTP
(“tty stop”)到程序,暂停它:
kill -TSTP [processid]
And the bg
command just sends it a SIGCONT
:
该bg
命令只是向它发送一个SIGCONT
:
kill -CONT [processid]
回答by Ignacio Vazquez-Abrams
You don't. You put an ampersand after the command.
你没有。你在命令后加一个 & 号。
command1 &
command2 &
command3 &