在程序中稍后杀死进程ID?

时间:2016-01-22 18:52:32

标签: linux bash terminal kill pid

我正在分配一个进程ID,特别是一个打开的终端,它自己运行一个脚本。我已经把那部分搞定了。我可以分配它然后立即杀死它,但是如果我尝试做一些像if逻辑语句那样的逻辑然后在逻辑完成之后,尝试杀死相同的processid变量,它说无法找到进程id。例如:

gnome-terminal (run a command in the terminal blah blah) & p1=$!;

kill $p1

上面完成时工作正常。但如果我想这样做:

gnome-terminal (run a command in the terminal blah blah) & p1=$!;

insert if statement with new terminal opened and closed on same line

exit if statement

kill $p1

我明白了:

  

第58行:kill:{14638}:参数必须是进程或作业ID

我是否可能以不正确的顺序做某事?

如果需要澄清,请告诉我。

0 个答案:

没有答案
相关问题