当前位置:网站首页>nohup principle
nohup principle
2022-07-31 07:09:00 【Hermokrates】
nohup
nohup Execution ignores the signal SIGHUP
,并将 stdout/stderr
重定向到文件 nohup.out
.以便shellCommands can continue to run in the background after shutdown or logout .nohupThe job is to let nohup After the command is not current shell 的子命令.而是PPID=1的进程(进程的PPID=1).This case cannot be brought back to the front desk.
signal (SIGHUP, SIG_IGN); // 忽略信号SIGHUP
char **cmd = argv + optind;
execvp (*cmd, cmd); // 在执行这个命令,而不是当前shell
For output redirection,对于STDOUT/STDERR会忽略,然后写入到 nohup.out
ignoring_input = isatty (STDIN_FILENO);
redirecting_stdout = isatty (STDOUT_FILENO);
stdout_is_closed = (!redirecting_stdout && errno == EBADF);
redirecting_stderr = isatty (STDERR_FILENO);
/* If standard input is a tty, replace it with /dev/null if possible. Note that it is deliberately opened for *writing*, to ensure any read evokes an error. */
if (ignoring_input)
{
if (fd_reopen (STDIN_FILENO, "/dev/null", O_WRONLY, 0) < 0)
error (exit_internal_failure, errno,
_("failed to render standard input unusable"));
if (!redirecting_stdout && !redirecting_stderr)
error (0, 0, _("ignoring input"));
}
/* If standard output is a tty, redirect it (appending) to a file. First try nohup.out, then $HOME/nohup.out. If standard error is a tty and standard output is closed, open nohup.out or $HOME/nohup.out without redirecting anything. */
if (redirecting_stdout || (redirecting_stderr && stdout_is_closed))
{
char *in_home = NULL;
char const *file = "nohup.out";
int flags = O_CREAT | O_WRONLY | O_APPEND;
mode_t mode = S_IRUSR | S_IWUSR;
mode_t umask_value = umask (~mode);
out_fd = (redirecting_stdout
? fd_reopen (STDOUT_FILENO, file, flags, mode)
: open (file, flags, mode));
边栏推荐
猜你喜欢
随机推荐
Skywalking UI使用
11.0 堆参数调优入门之堆参数调整
Third-party library-store
零样本学习&Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning
shell之条件语句(test、if、case)
接口报错no message avaliable
防抖和节流
What is float?What is document flow?Several ways and principles of clearing floats?What is BFC, how to trigger BFC, the role of BFC
Debian 10 iptables (防火墙)配置
【编程题】【Scratch三级】2022.03 冬天下雪了
浅析伪类和伪元素
Dart入门
SSH远程管理
tidyverse笔记——tidyr包
postgresql源码学习(33)—— 事务日志⑨ - 从insert记录看日志写入整体流程
编辑时过滤当前节点及根据限制的层数过滤数据
LVM和磁盘配额
【云原生】-Docker安装部署分布式数据库 OceanBase
Detailed explanation of js prototype
Debian 10 dhcp 服务配置