当前位置:网站首页>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));
边栏推荐
猜你喜欢
Oracle入门 02 - IT软硬件平台及操作系统介绍
12.0 堆参数调优入门之GC收集日志信息
Debian 10 配置网卡,DNS,IP地址
Analysis of the principle and implementation of waterfall flow layout
LXC的安装与配置使用
Redux state management
浅析重复线性渐变repeating-linear-gradient如何使用
Analysis of the implementation principle and detailed knowledge of v-model syntactic sugar and how to make the components you develop support v-model
【云原生】-Docker容器迁移Oracle到MySQL
进程和计划任务管理
随机推荐
第三方库-store
In-depth analysis of z-index
tidyverse笔记——dplyr包
磁盘管理与文件系统
拉格朗日插值及其应用
NFS共享存储服务
浅析伪类和伪元素
Oracle入门 02 - IT软硬件平台及操作系统介绍
一文读懂 MongoDB 和 MySQL 的差异
PXE高效批量网络装机
简单谈谈Feign
DNS域名解析服务
Basic usage of Koa framework
对van-notice-bar组件定义内容进行设置
银河麒麟高级服务器v10 sp1 手动加载Raid卡驱动
防抖和节流
搭建zabbix监控及邮件报警(超详细教学)
安装gstreamer开发依赖库到项目sysroot目录
线程唤醒机制
2022.7.29 数组