免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2575 | 回复: 6
打印 上一主题 下一主题

使用. 运行脚本后无法停止了 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-04 17:35 |只看该作者 |倒序浏览
使用". foo.sh"运行脚本后无法停止了,设定的Ctrl-\都不行了,想杀进程,可是"ps aux |grep foo"却找不到相应的进程。

下面是我的脚本:

$cat -n foo.sh
     1  #!/bin/bash
     2
     3  trap "" 2
     4  trap 'exitprocess' 3
     5  LOOP=0
     6
     7  exitprocess()
     8  {
     9  echo "You Just hit <CTRL-\>, at number $LOOP"
    10  echo "I will now exit"
    11  exit 1
    12  }
    13
    14  while :
    15  do
    16    LOOP=$[ $LOOP+1 ]
    17    echo $LOOP
    18    sleep 1
    19  done
$

[ 本帖最后由 Ph4t0m 于 2008-9-4 17:43 编辑 ]

论坛徽章:
3
CU大牛徽章
日期:2013-03-13 15:29:07CU大牛徽章
日期:2013-03-13 15:29:49CU大牛徽章
日期:2013-03-13 15:30:19
2 [报告]
发表于 2008-09-04 17:37 |只看该作者
ps aux |grep sh 看看

论坛徽章:
0
3 [报告]
发表于 2008-09-04 17:39 |只看该作者
ps 分析一下看是哪个进程

论坛徽章:
0
4 [报告]
发表于 2008-09-04 17:50 |只看该作者
我怀疑就是20263这个进程,但是现在的情况很奇怪,kill提示没有进程了,ps还能看到,脚本也还在跑。

$ps aux | grep sh | grep abc
abc       2131  0.0  0.0  61128   720 pts/1    S+   17:43   0:00 grep sh
root      7252  0.0  0.0  97008  3464 ?        Ss   13:36   0:00 sshd: abc [priv]
abc       7254  0.0  0.0  97140  1680 ?        S    13:37   0:00 sshd: abc@pts/21
abc       7255  0.0  0.0  64160  1548 pts/21   Ss+  13:37   0:00 -bash
root     10987  0.0  0.0  97004  3452 ?        Ss   16:00   0:00 sshd: abc [priv]
abc      10991  0.0  0.0  97136  1692 ?        S    16:00   0:00 sshd: abc@pts/0  
abc      10992  0.0  0.0  64288  1640 pts/0    Ss   16:00   0:00 -bash
root     13992  0.0  0.0  97004  3456 ?        Ss   17:06   0:00 sshd: abc [priv]
abc      13994  0.0  0.0  97136  1692 ?        S    17:06   0:00 sshd: abc@pts/1  
abc      13995  0.0  0.0  64284  1632 pts/1    Ss   17:06   0:00 -bash
abc      20623  0.0  0.0  64288  1592 pts/35   Ss   11:26   0:00 /bin/bash
abc@~/tmp/trap_s$kill 20263
abc@~/tmp/trap_s$kill 20263                 
-bash: kill: (20263) - No such process
abc@~/tmp/trap_s$ps aux | grep sh | grep abc
abc       2271  0.0  0.0  61124   716 pts/1    S+   17:45   0:00 grep sh
root      7252  0.0  0.0  97008  3464 ?        Ss   13:37   0:00 sshd: abc [priv]
abc       7254  0.0  0.0  97140  1680 ?        S    13:37   0:00 sshd: abc@pts/21
abc       7255  0.0  0.0  64160  1548 pts/21   Ss+  13:37   0:00 -bash
root     10987  0.0  0.0  97004  3452 ?        Ss   16:00   0:00 sshd: abc [priv]
abc      10991  0.0  0.0  97136  1692 ?        S    16:00   0:00 sshd: abc@pts/0  
abc      10992  0.0  0.0  64288  1640 pts/0    Ss   16:00   0:00 -bash
root     13992  0.0  0.0  97004  3456 ?        Ss   17:06   0:00 sshd: abc [priv]
abc      13994  0.0  0.0  97136  1692 ?        S    17:06   0:00 sshd: abc@pts/1  
abc      13995  0.0  0.0  64284  1632 pts/1    Ss   17:06   0:00 -bash
abc      20623  0.0  0.0  64288  1592 pts/35   Ss   11:26   0:00 /bin/bash
$

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
5 [报告]
发表于 2008-09-04 18:06 |只看该作者

回复 #4 Ph4t0m 的帖子

20263 还是 20623?

论坛徽章:
0
6 [报告]
发表于 2008-09-04 18:45 |只看该作者

回复 #5 blackold 的帖子

汗,刚才看花眼了。

不过我把所有可疑的bash进程杀掉后,程序还是在运行。
而键“CTRL-C”和“CTRL-Z”都无效,下面是相关信息,各位也可以在自己机器上试一试看看。

226
227
228
229
230
Quit
231
Quit
232
Quit
233
Quit
234
Quit
235
Quit
236
237

[92]+  Stopped                 sleep 1
238

[93]+  Stopped                 sleep 1
239

[94]+  Stopped                 sleep 1
240

[95]+  Stopped                 sleep 1
241

[96]+  Stopped                 sleep 1
242
243

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
7 [报告]
发表于 2008-09-05 08:11 |只看该作者
fuser -k /dev/pts/21
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP