gpt4 book ai didi

linux - 更改已运行进程的信号处理 (SIGHUP)

转载 作者:太空狗 更新时间:2023-10-29 11:39:42 24 4
gpt4 key购买 nike

假设我在后台启动了 Linux 进程。它不是守护进程,只是一个实用程序。如果它收到 SIGHUP,它就会被杀死。

我没有采取“nohup”预防措施。这已经比我想象的要花费更长的时间。
运行 4 小时后,ssh session 可能会断开连接。但我不想失去这个过程。
我想防止它被 SIGHUP 杀死。

是否有可能做出等同于

   signal(SIGHUP, SIG_IGN); 

在不重新启动这个进程的情况下?

谢谢

最佳答案

使用disown(1)

disown: disown [-h] [-ar] [jobspec ...] Remove jobs from current shell.

Removes each JOBSPEC argument from the table of active jobs.  Without
any JOBSPECs, the shell uses its notion of the current job.

Options:
-a remove all jobs if JOBSPEC is not supplied
-h mark each JOBSPEC so that SIGHUP is not sent to the job if
the shell receives a SIGHUP
-r remove only running jobs

Detaching a process from terminal, entirely

"disown" is a bash builtin that removes a shell job from the shell's job list. What this basically means is that you can't use "fg", "bg" on it anymore, but more importantly, when you close your shell it won't hang or send a SIGHUP to that child anymore. Unlike "nohup", "disown" is used after the process has been launched and backgrounded.

关于linux - 更改已运行进程的信号处理 (SIGHUP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6090160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com