Linux维护日记:如何让程序后台运行?

本文介绍如何使用nohup命令在Linux环境下使进程在后台持续运行,即使用户退出shell也能继续执行。通过简单的命令示例展示了nohup的基本用法,并解释了nohup.out文件的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有时候需要在后台开启服务,比如启动服务,当然希望shell退出后仍然执行,这时可以用nohup命令.

使用非常简单,比如要运行startup.sh作为后台服务,那么输入如下命令就可以

nohup ./startup.sh &

在当前目录下会产生一个文件:nohup.out,输入:tail -f nohup.out 就能看到了

附:Man nohup

nohup(1) - Linux man page

Name

nohup  - run a command immune to hangups, with output to a non-tty

Synopsis

nohup   COMMAND  [ ARG ]...
nohup   OPTION

Description

Run COMMAND, ignoring hangup signals.

--help
display this help and exit
--version
output version information and exit

If standard input is a terminal, redirect it from /dev/null. If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise. If standard error is a terminal, redirect it to standard output. To save output to FILE, use 'nohupCOMMAND > FILE'.

NOTE: your shell may have its own version of nohup, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值