linux如何将一个正在运行的进程转入到后台执行

本文介绍如何将前台进程转为后台运行,并确保即使在退出shell后进程仍能继续执行的方法。通过使用组合键Ctrl+Z暂停当前进程,接着利用bg命令将其转入后台运行,最后使用disown -h命令确保进程不会因终端关闭而被终止。

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

要求:将一个正在当前前台执行的进程转入后台执行,并且要求退出shell后依然保持不退出进程。

  1. ctrl+zto stop (pause) the program and get back to the shell

  2. bgto run it in the background

  3. disown -h [job-spec]where [job-spec] is the job number (like%1for the first running job; find about your number with thejobscommand) so that the job isn't killed when the terminal closes

 

操作如下:

[root@dispatch_19 gcc-4.8.1]# cd /home/machen/vv_cold_algorithm/movie_score_builder && /usr/local/bin/python view_record_manage.py save 1
13-12-28 13:50:49 ./logs/view_record.log INFO   start calculate delta data
13-12-28 13:50:49 ./logs/view_record.log INFO   hdfs:/data/dm/recommend/recom_yvv/20131227
first fresh...


ctrl+z
[1]+  Stopped                 /usr/local/bin/python view_record_manage.py save 1
[root@dispatch_19 movie_score_builder]#bg
[1]+ /usr/local/bin/python view_record_manage.py save 1 &
[root@dispatch_19 movie_score_builder]#jobs
[1]+  Running                 /usr/local/bin/python view_record_manage.py save 1 &
[root@dispatch_19 movie_score_builder]# disown  -h %1

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值