nohup(no hang-up)命令用于在后台运行程序,使程序在用户退出登录后继续运行。要使用nohup处理并发任务,您可以结合使用&符号将多个任务放入后台运行。以下是一些示例:
nohup your_command &
nohup your_command1 & nohup your_command2 & nohup your_command3 &
wait命令等待所有后台任务完成:nohup your_command1 & nohup your_command2 & nohup your_command3 &
wait
jobs命令查看后台任务的状态:nohup your_command1 & nohup your_command2 & nohup your_command3 &
jobs
fg命令将后台任务切换到前台运行:nohup your_command1 & nohup your_command2 & nohup your_command3 &
fg %1 # 切换到第一个后台任务
请注意,使用nohup命令时,输出会被重定向到名为nohup.out的文件。如果您想将输出重定向到其他文件,可以使用以下命令:
nohup your_command > output.log &
这将把your_command的输出保存到output.log文件中,而不是默认的nohup.out文件。