• 请不要在回答技术问题时复制粘贴 AI 生成的内容
hello826
V2EX  ›  程序员

Linux 如何恢复误 kill 的进程

  •  
  •   hello826 · Jun 18, 2020 · 5372 views
    This topic created in 2169 days ago, the information mentioned may be changed or developed.

    最近遇到一个问题,在服务器上要 kill 一个进程,用 ps 查出进程 Id 后,手动输入 kill -9 进程 id 。

    本来进程 ID 是 12349 结果手一抖输入了个 12340,正好有个进程的 ID 是 12340,然后就被误杀了。

    我想请教各位,如何能知道我误杀的 ID 12340 对应的进程,这样我也好重启。

    问了几个运维有的说看 /var/log/syslog 的 message 的,有的说让我一个一个检查服务的。。。。关键测试服务器上部署了 2~30 个服务。

    感觉手动检查可行性不高,各位有没有遇到过这个问题

    20 replies    2020-06-19 21:35:22 +08:00
    klesh
        1
    klesh  
       Jun 18, 2020 via Android
    往回滚看看之前的 ps 输出?
    lp10
        2
    lp10  
       Jun 18, 2020
    应该只能翻日志找有没有这个 PID 了……

    https://serverfault.com/questions/386956/pid-history-of-a-process
    itechify
        3
    itechify  
    PRO
       Jun 18, 2020 via Android
    因为这个每次 kill 之前都是复制粘贴,不相信自己手打 pid,而且复制也要检查一边😂
    hello826
        4
    hello826  
    OP
       Jun 18, 2020
    @oneisall8955 看来得改习惯,不能手动输入了。万一在生产环境输错了,那可就凉透了
    jimmyismagic
        5
    jimmyismagic  
       Jun 18, 2020
    又不是删库,怕什么,服务监控做好,啥都不要怕
    d0m2o08
        6
    d0m2o08  
       Jun 18, 2020
    别慌,谁都有尿鞋上的时候,淡定
    Latin
        7
    Latin  
       Jun 18, 2020
    ps -ef | grep `Search` | awk '{print $2}'|xargs kill -9
    bkmi
        8
    bkmi  
       Jun 18, 2020 via Android
    重启大法好
    no1xsyzy
        9
    no1xsyzy  
       Jun 18, 2020
    如果是 systemd
    # systemctl start $(systemctl get-default)
    如果你的系统重启之后可以自动开启所有需要的服务,这个就行。
    其他 init 也有类似的操作。
    no1xsyzy
        10
    no1xsyzy  
       Jun 18, 2020
    而且我觉得你可以去水一发 unix.stackexchange (
    yanqiyu
        11
    yanqiyu  
       Jun 18, 2020 via Android
    systemctl list-units --failed
    看看谁挂了,要是都没挂就不是问题
    githubhaoliu
        12
    githubhaoliu  
       Jun 18, 2020
    这时候就提现出了 supervisor 的重要性
    takemeaway
        13
    takemeaway  
       Jun 18, 2020
    日志应该可以的,有记录每次程序启动的 pid
    guanhui07
        14
    guanhui07  
       Jun 18, 2020
    supervisor 拉起来
    nightwitch
        15
    nightwitch  
       Jun 18, 2020
    别怂,杀到了重要的服务 systemed 配置了 restart 项的话会自动拉起来的
    hello826
        16
    hello826  
    OP
       Jun 18, 2020 via iPhone
    那像我这种极端环境,没有部署监控的话,只能一个一个去检查进程了吧
    peachpeach
        17
    peachpeach  
       Jun 18, 2020 via iPhone
    以上。
    lpts007
        18
    lpts007  
       Jun 19, 2020
    @githubhaoliu 你好,kill -9 杀掉的 也会拉起来吗? 我自己刚刚使用 supervisor,发现通过 kill -9 杀死的不会拉起( kill 可以拉起),是不是需要配置什么参数才行?
    githubhaoliu
        19
    githubhaoliu  
       Jun 19, 2020   ❤️ 1
    @lpts007 supervisor 是监听进程,不太关注你用什么命令 kill,只要进程退出就会拉起,只要你的 supervisor 在运行。
    lpts007
        20
    lpts007  
       Jun 19, 2020
    @githubhaoliu 好的 谢谢 看见你说的我又去检查了一下,我的描述确实不对---我没配 autorestart--都起不来。已经改了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   952 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 61ms · UTC 21:12 · PVG 05:12 · LAX 14:12 · JFK 17:12
    ♥ Do have faith in what you're doing.