免费注册 查看新帖 |

Chinaunix

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

nohup或者job control在ksh和bash下表现不同,ksh下程序会挂起导致问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-08 02:04 |只看该作者 |倒序浏览
本帖最后由 可可火山 于 2012-03-08 02:05 编辑

最近发现原来在solaris 8下工作的项目代码换到solairs 10后老是会挂起。程序虽然在运行但是部分功能不工作了。

项目程序对几个信号都做了自己的处理,同时脚本中大量用了nohup,solaris 10下不一定会挂,一般启动后能工作一段时间才出现问题,但是有时候可能一直是好的

nohup使用例子,实际项目中更加复杂,还在测试。
#!/bin/sh
nohup application </dev/null >application.log 2>&1 &

=======================ksh====================================================================================
  1. user:/export/home/user/termsignaltest# /usr/ucb/ps -auxww | grep $$ | grep -v grep
  2. user  27584  0.0  0.0 1920 1592 pts/15   S 16:38:47  0:00 -ksh
  3. user:/export/home/user/termsignaltest# /usr/ucb/ps -auxww | grep zsched| grep -v grep
  4. root     27910  0.0  0.0    0    0 ?        S   Feb 08  0:00 zsched
  5. user:/export/home/user/termsignaltest# nohup ./termsignals.sol10.bin </dev/null >termsignals.sol10.bin307 2>&1 &
  6. [1]     3034
  7. user:/export/home/user/termsignaltest# jobs
  8. [1] +  Running                 nohup ./termsignals.sol10.bin </dev/null >termsignals.sol10.bin.nohupo1 &
  9. user:/export/home/user/termsignaltest#
  10. user:/export/home/user/termsignaltest# exit
  11. You have running jobs
  12. user:/export/home/user/termsignaltest# exit
  13. Connection to solaris10.server.com closed.
复制代码


###另一个窗口观察输出
  1. user:/export/home/user/termsignaltest# tail -f termsignals.sol10.bin.nohupout.ksh.20120307
  2. checksighnal [20]       PID[3034]       PPID[27584]     The time is: Wed Mar 07 16:41:17 2012
  3. checksighnal [21]       PID[3034]       PPID[27584]     The time is: Wed Mar 07 16:41:22 2012
  4. sighup received...                                                                               //上面第二个exit的输出
  5. SIGHUG received
  6. checksighnal [22]       PID[3034]       PPID[27584]     The time is: Wed Mar 07 16:41:25 2012  
  7. checksighnal [23]       PID[3034]       PPID[27910]     The time is: Wed Mar 07 16:41:30 2012
  8. checksighnal [24]       PID[3034]       PPID[27910]     The time is: Wed Mar 07 16:41:35 2012
复制代码

=======================ksh end=================================================================================

=======================bash====================================================================================
  1. user:/export/home/user# bash
  2. user:/export/home/user# /usr/ucb/ps -auxww | grep $$ | grep -v grep
  3. user  26395  0.0  0.0 3560 2936 pts/15   S 16:43:48  0:00 bash
  4. user:/export/home/user# /usr/ucb/ps -auxww | grep zsched| grep -v grep
  5. root     27910  0.0  0.0    0    0 ?        S   Feb 08  0:00 zsched
  6. user:/export/home/user# cd termsignaltest
  7. user:/export/home/user/termsignaltest# nohup ./termsignals.sol10.bin </dev/null >termsignals.sol10.bi
  8. n.nohupout.bash.20120307 2>&1 &
  9. [1] 4527
  10. user:/export/home/user/termsignaltest# jobs
  11. [1]+  Running                 nohup ./termsignals.sol10.bin < /dev/null > termsignals.sol10.bin.nohupout.bash.20120307 2>&1 &
  12. user:/export/home/user/termsignaltest#
  13. user:/export/home/user/termsignaltest#
  14. user:/export/home/user/termsignaltest# exit
  15. exit
  16. user:/export/home/user# exit
  17. Connection to solaris10.server.com closed.
复制代码


###另一个窗口观察输出
  1. user:/export/home/user/termsignaltest# tail -f termsignals.sol10.bin.nohupout.bash.20120307
  2. signal check proc start....
  3. checksighnal [0]        PID[4527]       PPID[26395]     The time is: Wed Mar 07 16:45:14 2012
  4. checksighnal [1]        PID[4527]       PPID[26395]     The time is: Wed Mar 07 16:45:19 2012
  5. checksighnal [2]        PID[4527]       PPID[26395]     The time is: Wed Mar 07 16:45:24 2012
  6. checksighnal [3]        PID[4527]       PPID[26395]     The time is: Wed Mar 07 16:45:29 2012  //大概在这个时候跑exit
  7. checksighnal [4]        PID[4527]       PPID[26395]     The time is: Wed Mar 07 16:45:34 2012  //
  8. checksighnal [5]        PID[4527]       PPID[27910]     The time is: Wed Mar 07 16:45:39 2012
  9. checksighnal [6]        PID[4527]       PPID[27910]     The time is: Wed Mar 07 16:45:44 2012
  10. checksighnal [7]        PID[4527]       PPID[27910]     The time is: Wed Mar 07 16:45:49 2012
复制代码

=======================bash end=================================================================================

我的测试代码

  1. //termsignals.c
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <termios.h>
  5. #include <signal.h>
  6. #include <time.h>

  7. static volatile sig_atomic_t got_sighug;

  8. void exithandle(int sig);
  9. void printinfo(int id);

  10. int main (void)
  11. {
  12.         int tid=0;
  13.         if (sigset (SIGHUP, exithandle) == SIG_ERR){
  14.                 printf("err_msg sigset SIGHUP->exithandle\n");
  15.         }

  16.         printf("signal check proc start....\n");
  17.         fflush(NULL);

  18.         for (;;) {
  19.                 printinfo(tid++);
  20.                 sleep(5);
  21.                 if (got_sighug) {
  22.                         printf ("SIGHUG received\n");
  23.                         got_sighug = 0;
  24.                 }
  25.                 if(tid>9999) tid=0;
  26.         }
  27. }

  28. void exithandle(int sig)
  29. {
  30.         printf("sighup received... \n");
  31.         got_sighug = 1;
  32. }

  33. void printinfo(int id)
  34. {
  35.         time_t t;
  36.         struct tm *tm;
  37.         char buf[64];
  38.         t=time(NULL);
  39.         tm=localtime(&t);

  40.         strftime(buf,sizeof(buf),"%c",tm);
  41.         printf("checksighnal [%d]\tPID[%d]\tPPID[%d]\tThe time is: %s\n", id,getpid(),getppid(),buf);
  42.         fflush(NULL);
  43. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP