zoukankan      html  css  js  c++  java
  • Strace 的初步使用, 结合nginx

    Strace 的初步使用, 结合nginx

    一,安装

    sudo apt-get install strace
    
    测试中可能用到的命令
    ps -ef | grep nginx
    ps -eo pid,ppid,sid,tty,pgrp,comm | grep -E 'bash|PID|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
    

    启动nginx

    我们启动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追踪进程信号

    命令格式

    sudo strace -e trace=signal -p {pid}
    

    终端一,贴上strace

    cwl@cwl-PC:~$ sudo strace -e trace=signal -p 9761
    [sudo] cwl 的密码:
    strace: Process 9761 attached
    rt_sigsuspend([], 8
    

    终端二,断开nginx

    cwl@cwl-PC:/usr/local/nginx/sbin$ sudo ./nginx -s quit
    

    终端一,接收到信号

    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是一个最终信号的工具。扩展一下。如何关闭终端进程不退出呢?

    方法:

    • 拦截SIGHUP,然后自己处理
    • 与bash进程不在同一个sesion中
  • 相关阅读:
    Angular2 初识
    TypeScript 函数 (五)
    TypeScript 接口(三)
    TypeScript 基本类型(一)
    TypeScript 变量声明(二)
    Web API中的模型验证Model Validation
    DataContract 和 DataMember
    (推荐JsonConvert )序列化和反序列化Json
    9、DFA最小化,语法分析初步
    8.非确定的自动机NFA确定化为DFA
  • 原文地址:https://www.cnblogs.com/Q1143316492/p/10738804.html
Copyright © 2011-2022 走看看