网站制作学习网Linux→正文:linux 后台执行运行不退出
字体:

linux 后台执行运行不退出

Linux 2023/8/14 21:11:59  点击:不统计

%77w%77%2Ef%6F%72p%73%70%2Ec%6E
 在使用linux 部分命令时,需要长时间在 后台运行,后台执行,不因用户退出而退出,有下面两种方法实现后台运行不退出。

以运行php 为例
原始命令: php test.php >result.log
 
第一种,nohup命令
>nohup php test.php>result.log &
>jobs #查看任务号, []里面的就是任务号
> [1]  + running    nohup php test.php > result.log
>disown -h %1    //忽略这个作业的HUP信号
 
第二中,采用 暂停后执行,通过设置后台运行命令
(1)运行命令
>php test.php > result.log
(2)然后键盘按 ctrl + z 暂停
>[1]+ Stopped
 (3) 输入jobs 看后台任务号
> [1]  + running    nohup php test.php > result.log
看到任务号 1
(4)设置后台运行, 
>bg %1       // 输入 bg %1,将进程号为1的进程恢复到后台运行
 (5)使用disown -h 将这个作业忽略HUP信号:
>disown -h %1    //忽略这个作业的HUP信号
 
以上就是linux 后台运行不退出的命令

http://www.forasp.cn/

·上一篇:rsync 限制带宽,限速 >>    ·下一篇:shell统计linux ssh连接login失败ip次数 >>
推荐文章
最新文章