How to find the reason for a dead process without log file on unix?

前端 未结 4 702
陌清茗
陌清茗 2021-02-06 10:55

This is an interview question.

A developer started a process. But when a customer wants to use the process, he found the process wasn\'t running. The developer logged

相关标签:
4条回答
  • 2021-02-06 11:17

    If you have the disk space and spare CPU power, you can leave strace following the program to catch the sequence leading up to exit.

    One possible cause if the program died without leaving any trace is the Out-Of-Memory (OOM) killer. This will leave a message in the kernel log if it kills your process.

    From the same answer, process accounting can be modified to provide some clues by telling you the exit code along with the exit time.

    0 讨论(0)
  • 2021-02-06 11:31

    Sometimes programs don't create core dumps. In this case knowing the exit code of your software may help.

    So you can use this script below to start your software and log its exit status for finding its exit reason.

    Example :

    #!/bin/bash
    ./myprogram
    
    #get exit code
    exitvalue=$?
    
    #log exit code value to /var/log/messages
    logger -s "exit code of my program is " $exitvalue
    
    0 讨论(0)
  • 2021-02-06 11:42

    are there other ways to do it by referring some information generated by OS?

    core dump is one option.

    0 讨论(0)
  • 2021-02-06 11:43

    ... use a debugger like gdb ...

    0 讨论(0)
提交回复
热议问题