目錄html
sudo apt-get install strace
測試中可能用到的命令 ps -ef | grep nginx ps -eo pid,ppid,sid,tty,pgrp,comm | grep -E 'bash|PID|nginx'
我首先進入到nginx目錄下nginx
cwl@cwl-PC:/usr/local/nginx$ pwd /usr/local/nginx cwl@cwl-PC:/usr/local/nginx$ ls client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
啓動nginxbash
咱們啓動nginx, 拉起了四個進程工具
cwl@cwl-PC:/usr/local/nginx/sbin$ sudo ./nginx cwl@cwl-PC:/usr/local/nginx/sbin$ ps -ef | grep nginx root 9761 1 0 19:55 ? 00:00:00 nginx: master process ./nginx nobody 9762 9761 0 19:55 ? 00:00:00 nginx: worker process nobody 9763 9761 0 19:55 ? 00:00:00 nginx: worker process nobody 9764 9761 0 19:55 ? 00:00:00 nginx: worker process nobody 9765 9761 0 19:55 ? 00:00:00 nginx: worker process cwl 9778 15969 0 19:56 pts/0 00:00:00 grep nginx
cwl@cwl-PC:/usr/local/nginx/sbin$ ps -eo pid,ppid,sid,tty,pgrp,comm | grep -E 'bash|PID|nginx' PID PPID SID TT PGRP COMMAND 9761 1 9761 ? 9761 nginx 9762 9761 9761 ? 9761 nginx 9763 9761 9761 ? 9761 nginx 9764 9761 9761 ? 9761 nginx 9765 9761 9761 ? 9761 nginx 11165 11135 11165 pts/2 11165 bash 15969 15947 15969 pts/0 15969 bash 16497 16476 16497 pts/1 16497 bash
strace追蹤進程信號測試
命令格式ui
sudo strace -e trace=signal -p {pid}
終端一,貼上stracerest
cwl@cwl-PC:~$ sudo strace -e trace=signal -p 9761 [sudo] cwl 的密碼: strace: Process 9761 attached rt_sigsuspend([], 8
終端二,斷開nginxcode
cwl@cwl-PC:/usr/local/nginx/sbin$ sudo ./nginx -s quit
終端一,接收到信號htm
strace: Process 9761 attached rt_sigsuspend([], 8) = ? ERESTARTNOHAND (To be restarted if no handler) --- SIGQUIT {si_signo=SIGQUIT, si_code=SI_USER, si_pid=12201, si_uid=0} --- rt_sigreturn({mask=[HUP INT QUIT USR1 USR2 ALRM TERM CHLD WINCH IO]}) = -1 EINTR (Interrupted system call) rt_sigsuspend([], 8) = ? ERESTARTNOHAND (To be restarted if no handler) --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9762, si_uid=65534, si_status=0, si_utime=0, si_stime=0} --- rt_sigreturn({mask=[HUP INT QUIT USR1 USR2 ALRM TERM CHLD WINCH IO]}) = -1 EINTR (Interrupted system call) rt_sigsuspend([], 8) = ? ERESTARTNOHAND (To be restarted if no handler) --- SIGIO {si_signo=SIGIO, si_code=SI_KERNEL} --- rt_sigreturn({mask=[HUP INT QUIT USR1 USR2 ALRM TERM CHLD WINCH IO]}) = -1 EINTR (Interrupted system call) rt_sigsuspend([], 8) = ? ERESTARTNOHAND (To be restarted if no handler) --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9763, si_uid=65534, si_status=0, si_utime=0, si_stime=0} --- rt_sigreturn({mask=[HUP INT QUIT USR1 USR2 ALRM TERM CHLD WINCH IO]}) = -1 EINTR (Interrupted system call) rt_sigsuspend([], 8) = ? ERESTARTNOHAND (To be restarted if no handler) --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9764, si_uid=65534, si_status=0, si_utime=0, si_stime=0} --- --- SIGIO {si_signo=SIGIO, si_code=SI_KERNEL} --- rt_sigreturn({mask=[CHLD]}) = 0 rt_sigreturn({mask=[HUP INT QUIT USR1 USR2 ALRM TERM CHLD WINCH IO]}) = -1 EINTR (Interrupted system call) +++ exited with 0 +++
strace是一個最終信號的工具。擴展一下。如何關閉終端進程不退出呢?進程
方法: