当你有需求将一个进程放在后台跑时,切忌使用nohup or screen.
screen需要在你run脚本之前运行,nohup可以修改已经运行的进程。
/usr/bin/nohup command [argument...]
/usr/bin/nohup -p [-Fa] pid [pid...]
/usr/bin/nohup -g [-Fa] gpid [gpid...]
/usr/xpg4/bin/nohup command [argument...]
[@more@]We can try to use solaris dtrace to check what happens internally.
bash-3.00# cat sig.d
#!/usr/sbin/dtrace -s
proc:::signal-send
/args[1]->pr_fname == $$1/
{
printf("%s(pid:%d ) is sending signal %d to %s (pid:%d ppid:%d)n", execname, pid, args[2],args[1]->pr_fname, args[1]->pr_pid,args[1]->pr_ppid);
}
bash-3.00# cat proc.d
#!/usr/sbin/dtrace -s
proc:::signal-handle
/execname=="sleep"/
{
printf("sleep process information (pid:%d ppid:%d)n",pid,ppid);
}
Session1: ./sig.d sleep
Session2: ./proc.d
TEST1:
Session3: sleep 10000 &
And then quit this terminal.
Session1:
CPU ID FUNCTION:NAME
1 4592 sigtoproc:signal-send bash(pid:1382 ) is sending signal 1 to sleep (pid:1441 ppid:1382)
Session2:
CPU ID FUNCTION:NAME
0 4590 psig:signal-handle sleep process information (pid:1441 ppid:1382)
Test2:
Session3: nohup sleep 10000 &
close the terminal, no signal received.
Try to kill -9:
Session1:
0 4592 sigtoproc:signal-send sh(pid:1424 ) is sending signal 9 to sleep (pid:1428 ppid:1382)
Session2:
0 4590 psig:signal-handle sleep process information (pid:1428 ppid:1382)
Test3:
Session3:
bash-3.00# while(true); do sleep 10; done &
bash-3.00# ptree 1736
628 /usr/lib/ssh/sshd
1690 /usr/lib/ssh/sshd
1691 /usr/lib/ssh/sshd
1699 -sh
1733 bash
1734 bash
1736 sleep 10
exit this terminal, you will hung there when "exit", this time you need to close that opened tab by yourself, like ALT+F4 in secureCRT.
You can find the sleep is still running, but parent process 1734 now was taken by the the top process:
# ptree 1734
1734 bash
1794 sleep 10
kill -9 1734 => parent process changed to 1
# ps -ef|grep sleep
root 1812 1 0 15:54:39 ? 0:00 sleep 10
Still no signal was received for that sleep process, until it's parent process changes to 1, it quit out the while loop.
# ps -ef|grep sleep
#
For sqlplus, it’s hard to say if you exit your terminal, will the oracle process killed. This is actually controlled by oracle process now, not the operation system.
We have below situations:
1. You tried to kill a parent process, but it’s child process still keep running .
2. Killed the sqlplus, but the LOCAL=NO oracle process still there and keep running. It may exists until it needs to talk to the OS process and PMON tries to rollback and clean. Sometimes like creating a temp table or index, it may succeed even you kill that os process.
3. This is different from “defunct” process, defunct process was caused by child process dying but parent process didn’t handle waitpid or SIGCHLD signal.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21084389/viewspace-1034516/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/21084389/viewspace-1034516/