nohup
(no hang-up)命令用于在Linux中使进程忽略挂起(SIGHUP)信号,从而在用户退出登录后继续运行
与命令直接组合使用:
nohup command &
这将在后台运行command
,并将输出重定向到名为nohup.out
的文件。
与管道(pipe)组合使用:
nohup command1 | command2 &
这将在后台运行command1
,将其输出作为command2
的输入,并将command2
的输出重定向到名为nohup.out
的文件。
与子shell组合使用:
nohup bash -c 'command1; command2' &
这将在后台运行一个子shell,依次执行command1
和command2
,并将子shell的输出重定向到名为nohup.out
的文件。
与&
符号组合使用:
command1 & nohup command2 &
这将在后台分别运行command1
和command2
,并将它们的输出都重定向到名为nohup.out
的文件。
与disown
命令组合使用:
nohup command & disown
这将在后台运行command
,并将其从当前shell的作业表中移除,使其在用户退出登录后继续运行。
请注意,nohup
命令通常与&
符号一起使用,以便在后台运行进程。同时,为了避免输出到终端,建议将输出重定向到一个文件,如nohup.out
。