当前位置:网站首页>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));
边栏推荐
猜你喜欢
随机推荐
对van-notice-bar组件定义内容进行设置
vmware搭建redis集群遇到问题
什么是浮动?什么是文档流?清除浮动的几种方式及原理?什么是BFC,如何触发BFC,BFC的作用
拉格朗日插值及其应用
数据库原理作业2 — JMU
2022.7.29 数组
Bulk free text translation
Oracle入门 07 - Linux 操作系统安装配置(REHL 7.x)
TypeScript基本类型
选择排序法
CHI论文阅读(1)EmoGlass: an End-to-End AI-Enabled Wearable Platform for Enhancing Self-Awareness of Emoti
服务器硬件及RAID配置实战
Install the gstreamer development dependency library to the project sysroot directory
js原型详解
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
Zabbix 配置详解
Shell编程规范与变量
Detailed explanation of js prototype
4-1-7 二叉树及其遍历 家谱处理 (30 分)
10.0 堆体系结构概述之元空间/永久代