从shell脚本或直接在终端中调用kill时有什么区别

时间:2013-02-17 08:55:51

标签: macos shell terminal kill

我正试图通过此shell脚本中的ID来终止进程。

# based on
# http://stackoverflow.com/questions/6437602/shell-script-to-get-the-process-id-on-linux
output=`ps -ax|grep Ad[o]be\ After\ Effects\ CS6`;
# set -- parses the ps output into words,
# and $1 is the first word on the line
# which happens to be the process ID
set -- $output;
pid=$1;
echo "I'm about to kill process " $pid;
killall -SEGV $pid;

但那给了我那个结果

No matching processes belonging to you were found  

当我使用相同的ID时,我的脚本会回显并直接执行命令,它会做它应该做的事情。

kill -SEGV 50283  

那么差异是什么? 我需要做些什么才能使我的脚本表现得像'我'(我认为这是用户权利的东西)?

1 个答案:

答案 0 :(得分:1)

在您的脚本中,您说killall按名称查找进程。在你的终端中,你说kill取一个PID。前者是错误的,但可以说你应该在脚本中使用killall而不是自己实现类似的东西。