我发现 ps 或 pgrep 找不到没有“#!/bin/bash”的运行脚本
这是一个sample.sh:
while true
do
echo $(date)
done
启动脚本(ubuntu 18.04,Linux 版本 4.15.0-101-generic):
$echo $BASH
/bin/bash
./sample.sh
打开另一个终端,ps只找到命令grep
$ps -aux |grep sample.sh
16887 0.0 0.0 16184 1008 pts/4 S+ 07:12 0:00 grep --color=auto sample
pgrep 一无所获
$pgrep sample
$
但是如果我在 sample.sh 中添加“#!/bin/bash”,现在一切正常:
#!/bin/bash <-----add this line
while true
do
echo $(date)
done
我想知道为什么。