busybox shell 执行一个死循环脚本,为什么ps 有时看到多个脚本进程(附示例代码)

角落的青苔 2016-01-29 03:45:09
testFree.sh 脚本内容如下:

#!/bin/sh
#上一次记录时的剩余内存
preFree=4096000
#有多少秒未记录了
timeEsc=0

while true
do
stmp=`free -k | grep "Mem"`
OSMem_free=`echo $stmp | awk '{print $4}'`

let nDiff="$preFree-$OSMem_free"
let timeEsc="$timeEsc+1"
if [ $nDiff -ge 2048 ] || [ $nDiff -lt -2048 ] || [ $timeEsc -ge 6000 ] ; then
echo .
fi
done


执行脚本
./testFree.sh >> /dev/null

在另一个终端不停执行
# ps | grep testF | grep -v grep
24259 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
# ps | grep testF | grep -v grep
24259 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
29774 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
# ps | grep testF | grep -v grep
24259 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
# ps | grep testF | grep -v grep
24259 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
# ps | grep testF | grep -v grep
1570 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
24259 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
# ps | grep testF | grep -v grep
3317 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
24259 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
# ps | grep testF | grep -v grep
24259 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
# ps | grep testF | grep -v grep
24259 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
# ps | grep testF | grep -v grep
6961 root 0 RW [testFree.sh]
24259 root 1752 R {testFree.sh} /bin/sh ./testFree.sh
# ps | grep testF | grep -v grep
24259 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
# ps | grep testF | grep -v grep
9738 root 1752 S {testFree.sh} /bin/sh ./testFree.sh
24259 root 1752 S {testFree.sh} /bin/sh ./testFree.sh

========================
为什么有时会有两个 testFree.sh 在运行呢?注意观察 pid=24259 这个是本来真正运行的进程
...全文
646 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
nswcfd 2016-02-04
  • 打赏
  • 举报
回复
子进程刚被fork出来,但是还没有exec新的binary的时候,就是这个状态吧?
常书 2016-02-04
  • 打赏
  • 举报
回复
我这边也会出现,测试是由awk命令引起的,是不是它的实现会创建进程? 我的busybox是1.16.1
角落的青苔 2016-01-29
  • 打赏
  • 举报
回复
~ # ps | grep testF | grep -v grep 1400 root 0:03 {testFree.sh} /bin/sh ./testFree.sh 21188 root 0:00 {testFree.sh} /bin/sh ./testFree.sh ~ # ps | grep testF | grep -v grep 1400 root 0:03 {testFree.sh} /bin/sh ./testFree.sh ~ # ps | grep testF | grep -v grep 1400 root 0:03 {testFree.sh} /bin/sh ./testFree.sh 22124 root 0:00 {testFree.sh} /bin/sh ./testFree.sh 22125 root 0:00 {testFree.sh} /bin/sh ./testFree.sh 22126 root 0:00 {testFree.sh} /bin/sh ./testFree.sh ~ # ps | grep testF | grep -v grep 1400 root 0:03 {testFree.sh} /bin/sh ./testFree.sh ~ # ps | grep testF | grep -v grep 1400 root 0:03 {testFree.sh} /bin/sh ./testFree.sh 23294 root 0:00 {testFree.sh} /bin/sh ./testFree.sh ~ # ps | grep testF | grep -v grep 1400 root 0:03 {testFree.sh} /bin/sh ./testFree.sh 23858 root 0:00 {testFree.sh} /bin/sh ./testFree.sh 23862 root 0:00 {testFree.sh} /bin/sh ./testFree.sh 23863 root 0:00 {testFree.sh} /bin/sh ./testFree.sh ======================================= BusyBox v1.20.2 (2015-10-23 11:13:35 CST) multi-call binary /mnt/mtd # uname -a Linux (none) 3.10.0 #3 Tue Dec 29 16:35:18 CST 2015 armv7l GNU/Linux 是在 ARM 平台有问题(海思 35XX)。 在ubuntu 12.04 bash 下不会出现这个问题
KEL-1 2016-01-29
  • 打赏
  • 举报
回复
已经试验,没出现你所说的问题,另外你可以查看进程开始运行的时间 ,查看下进程来源

19,620

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧