- 论坛徽章:
- 0
|
本帖最后由 可可火山 于 2012-03-08 02:05 编辑
最近发现原来在solaris 8下工作的项目代码换到solairs 10后老是会挂起。程序虽然在运行但是部分功能不工作了。
项目程序对几个信号都做了自己的处理,同时脚本中大量用了nohup,solaris 10下不一定会挂,一般启动后能工作一段时间才出现问题,但是有时候可能一直是好的
nohup使用例子,实际项目中更加复杂,还在测试。
#!/bin/sh
nohup application </dev/null >application.log 2>&1 &
=======================ksh====================================================================================
- user:/export/home/user/termsignaltest# /usr/ucb/ps -auxww | grep $$ | grep -v grep
- user 27584 0.0 0.0 1920 1592 pts/15 S 16:38:47 0:00 -ksh
- user:/export/home/user/termsignaltest# /usr/ucb/ps -auxww | grep zsched| grep -v grep
- root 27910 0.0 0.0 0 0 ? S Feb 08 0:00 zsched
- user:/export/home/user/termsignaltest# nohup ./termsignals.sol10.bin </dev/null >termsignals.sol10.bin307 2>&1 &
- [1] 3034
- user:/export/home/user/termsignaltest# jobs
- [1] + Running nohup ./termsignals.sol10.bin </dev/null >termsignals.sol10.bin.nohupo1 &
- user:/export/home/user/termsignaltest#
- user:/export/home/user/termsignaltest# exit
- You have running jobs
- user:/export/home/user/termsignaltest# exit
- Connection to solaris10.server.com closed.
复制代码
###另一个窗口观察输出
- user:/export/home/user/termsignaltest# tail -f termsignals.sol10.bin.nohupout.ksh.20120307
- checksighnal [20] PID[3034] PPID[27584] The time is: Wed Mar 07 16:41:17 2012
- checksighnal [21] PID[3034] PPID[27584] The time is: Wed Mar 07 16:41:22 2012
- sighup received... //上面第二个exit的输出
- SIGHUG received
- checksighnal [22] PID[3034] PPID[27584] The time is: Wed Mar 07 16:41:25 2012
- checksighnal [23] PID[3034] PPID[27910] The time is: Wed Mar 07 16:41:30 2012
- checksighnal [24] PID[3034] PPID[27910] The time is: Wed Mar 07 16:41:35 2012
复制代码
=======================ksh end=================================================================================
=======================bash====================================================================================
- user:/export/home/user# bash
- user:/export/home/user# /usr/ucb/ps -auxww | grep $$ | grep -v grep
- user 26395 0.0 0.0 3560 2936 pts/15 S 16:43:48 0:00 bash
- user:/export/home/user# /usr/ucb/ps -auxww | grep zsched| grep -v grep
- root 27910 0.0 0.0 0 0 ? S Feb 08 0:00 zsched
- user:/export/home/user# cd termsignaltest
- user:/export/home/user/termsignaltest# nohup ./termsignals.sol10.bin </dev/null >termsignals.sol10.bi
- n.nohupout.bash.20120307 2>&1 &
- [1] 4527
- user:/export/home/user/termsignaltest# jobs
- [1]+ Running nohup ./termsignals.sol10.bin < /dev/null > termsignals.sol10.bin.nohupout.bash.20120307 2>&1 &
- user:/export/home/user/termsignaltest#
- user:/export/home/user/termsignaltest#
- user:/export/home/user/termsignaltest# exit
- exit
- user:/export/home/user# exit
- Connection to solaris10.server.com closed.
复制代码
###另一个窗口观察输出
- user:/export/home/user/termsignaltest# tail -f termsignals.sol10.bin.nohupout.bash.20120307
- signal check proc start....
- checksighnal [0] PID[4527] PPID[26395] The time is: Wed Mar 07 16:45:14 2012
- checksighnal [1] PID[4527] PPID[26395] The time is: Wed Mar 07 16:45:19 2012
- checksighnal [2] PID[4527] PPID[26395] The time is: Wed Mar 07 16:45:24 2012
- checksighnal [3] PID[4527] PPID[26395] The time is: Wed Mar 07 16:45:29 2012 //大概在这个时候跑exit
- checksighnal [4] PID[4527] PPID[26395] The time is: Wed Mar 07 16:45:34 2012 //
- checksighnal [5] PID[4527] PPID[27910] The time is: Wed Mar 07 16:45:39 2012
- checksighnal [6] PID[4527] PPID[27910] The time is: Wed Mar 07 16:45:44 2012
- checksighnal [7] PID[4527] PPID[27910] The time is: Wed Mar 07 16:45:49 2012
复制代码
=======================bash end=================================================================================
我的测试代码
- //termsignals.c
- #include <stdio.h>
- #include <unistd.h>
- #include <termios.h>
- #include <signal.h>
- #include <time.h>
- static volatile sig_atomic_t got_sighug;
- void exithandle(int sig);
- void printinfo(int id);
- int main (void)
- {
- int tid=0;
- if (sigset (SIGHUP, exithandle) == SIG_ERR){
- printf("err_msg sigset SIGHUP->exithandle\n");
- }
- printf("signal check proc start....\n");
- fflush(NULL);
- for (;;) {
- printinfo(tid++);
- sleep(5);
- if (got_sighug) {
- printf ("SIGHUG received\n");
- got_sighug = 0;
- }
- if(tid>9999) tid=0;
- }
- }
- void exithandle(int sig)
- {
- printf("sighup received... \n");
- got_sighug = 1;
- }
- void printinfo(int id)
- {
- time_t t;
- struct tm *tm;
- char buf[64];
- t=time(NULL);
- tm=localtime(&t);
- strftime(buf,sizeof(buf),"%c",tm);
- printf("checksighnal [%d]\tPID[%d]\tPPID[%d]\tThe time is: %s\n", id,getpid(),getppid(),buf);
- fflush(NULL);
- }
复制代码 |
|