当我kill
在命令行上使用时,它可以工作。
kill -SIGSTOP 1234
Run Code Online (Sandbox Code Playgroud)
但是如果我在 bash 脚本文件中使用,我会收到这个错误:
kill: SIGSTOP: invalid signal specification
Run Code Online (Sandbox Code Playgroud)
.sh 文件是
#!/bin/sh
kill -SIGSTOP 1234
Run Code Online (Sandbox Code Playgroud)
如何kill
在 bash 脚本中使用?我试过这个:
#!/bin/sh
/bin/bash -c "kill -SIGSTOP 1234"
Run Code Online (Sandbox Code Playgroud)
但它不起作用。
我结合top
并pidof
命令:
top -p $(pidof <process_name>)
Run Code Online (Sandbox Code Playgroud)
如果pidof <process_name>
返回一个 idtop
命令有效。但是如果pidof <process_name>
不止一个 idstop
命令不起作用。
pidof
返回 ID 之间有一个空格,例如: 123 124 125
如果我可以用逗号之类的123, 124, 125
top
命令获取这些 id就可以了。如何更改 的输出格式pidof
?
我知道awk
用于格式化文本数据。但是我找不到如何awk
用于 shell 命令的结果。