别忘了在disown之前执行bg命令,否则进程会一直stopped

别忘了在disown之前执行bg命令,否则进程会一直stopped

今天在Linux下测试程序,是直接执行的命令,如下所示:

[root@NODE22 bin]# ./cap
#======= CAP v20120216f =======#
prog-path: /root/work22/ct08/bin/
prog-name: cap
cfg_name='../cfg/cap.cfg'
loadconfig ok
checkconfig ok
System::Init ok
cap start ok, pid 8342

想到这个程序要在我下班之后继续执行,于是我就按下了Ctrl+Z

 


[1]+  Stopped                 ./cap

 

因为我准备关闭SecureCRT准备收工了,所以决定让它脱离我这个终端,执行了disown来做这件事

[root@NODE22 bin]# disown %1
-bash: warning: deleting stopped job 1 with process group 8342
[root@NODE22 bin]#

 

看看这个操作灵不灵,我看了一下日志,发现日志没有继续往下记录,正常情况应该往下记录的。

 

想起来,没有在disown之前执行bg命令,程序已经处于Stopped状态(看disown命令的输出),得让它继续往下执行

 

[root@NODE22 bin]# killall -CONT cap

 

日志也正常了。切记啊,切记啊:别忘了在disown之前执行bg命令

 

 

本文地址: http://codingstandards.iteye.com/blog/1408321

 

 

相关帮助信息:

[root@NODE22 eap_designer]# help disown
disown: disown [-h] [-ar] [jobspec ...]
    By default, removes each JOBSPEC argument from the table of active jobs.
    If the -h option is given, the job is not removed from the table, but is
    marked so that SIGHUP is not sent to the job if the shell receives a
    SIGHUP.  The -a option, when JOBSPEC is not supplied, means to remove all
    jobs from the job table; the -r option means to remove only running jobs.
[root@NODE22 eap_designer]# help bg
bg: bg [job_spec ...]
    Place each JOB_SPEC in the background, as if it had been started with
    `&'.  If JOB_SPEC is not present, the shell's notion of the current
    job is used.
[root@NODE22 eap_designer]# help fg
fg: fg [job_spec]
    Place JOB_SPEC in the foreground, and make it the current job.  If
    JOB_SPEC is not present, the shell's notion of the current job is
    used.
[root@NODE22 eap_designer]# help jobs
jobs: jobs [-lnprs] [jobspec ...] or jobs -x command [args]
    Lists the active jobs.  The -l option lists process id's in addition
    to the normal information; the -p option lists process id's only.
    If -n is given, only processes that have changed status since the last
    notification are printed.  JOBSPEC restricts output to that job.  The
    -r and -s options restrict output to running and stopped jobs only,
    respectively.  Without options, the status of all active jobs is
    printed.  If -x is given, COMMAND is run after all job specifications
    that appear in ARGS have been replaced with the process ID of that job's
    process group leader.
[root@NODE22 eap_designer]#

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux 中,有多种命令和脚本可以在子进程中运行,也有多种命令和脚本可以在当前进程中运行。下面将分别介绍这些命令和脚本。 1. 在子进程中运行的命令和脚本 (1)使用 & 符号 使用 & 符号可以将命令或脚本放在后台运行,这样就在子进程中运行。例如: ``` $ command & ``` (2)使用 nohup 命令 nohup 命令可以在后台运行命令或脚本,并且在终端关闭后仍然可以继续运行。例如: ``` $ nohup command & ``` (3)使用 disown 命令 disown 命令可以将正在运行的命令或脚本从当前 shell 话中分离,使其在后台继续运行。例如: ``` $ command & $ disown ``` 2. 在当前进程中运行的命令和脚本 (1)直接运行命令或脚本 在终端中直接输入命令或脚本名称并按下回车键,就可以在当前进程中运行。例如: ``` $ command ``` (2)使用 source 命令 使用 source 命令可以在当前进程中运行脚本,并且可以将脚本中定义的变量和函数导入到当前 shell 环境中。例如: ``` $ source script.sh ``` (3)使用 . 命令 使用 . 命令也可以在当前进程中运行脚本,并且可以将脚本中定义的变量和函数导入到当前 shell 环境中。例如: ``` $ . script.sh ``` 以上就是在 Linux 中常用的在子进程和当前进程中运行命令和脚本的方法。需要注意的是,不同的方法适用于不同的场景,需要根据具体情况选择适合的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值