jobs -x command 的作用是什么?说明不太理解,实验也没弄明白

其它类软件,非上述版软件
回复
科学之子
帖子: 2284
注册时间: 2013-05-26 6:58
系统: Debian 9

jobs -x command 的作用是什么?说明不太理解,实验也没弄明白

#1

帖子 科学之子 » 2016-07-28 11:08

jobs -x command 的作用是什么?说明不太理解,实验也没弄明白

代码: 全选

$ help jobs
jobs: jobs [-lnprs] [jobspec ...] or jobs -x command [args]
    Display status of jobs.
    
    Lists the active jobs.  JOBSPEC restricts output to that job.
    Without options, the status of all active jobs is displayed.
    
    Options:
      -l	lists process IDs in addition to the normal information
      -n	lists only processes that have changed status since the last
    	notification
      -p	lists process IDs only
      -r	restrict output to running jobs
      -s	restrict output to stopped jobs
    
    If -x is supplied, 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.
    
    Exit Status:
    Returns success unless an invalid option is given or an error occurs.
    If -x is used, returns the exit status of COMMAND.
但是我加上 -x参数后,command接收到的参数好像没有变化
我是到proc里看命令进程的"cmdline"文件
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: jobs -x command 的作用是什么?说明不太理解,实验也没弄明白

#2

帖子 vickycq » 2016-07-28 12:12

就是参数替换的作用
将 %n %str %?str %% %+ %- 替换成对应的PID

代码: 全选

$ cat bin/mytest 
#!/bin/bash
echo args: $*
sleep 3600

$ elinks
[1]+  Stopped                 elinks
$ pgrep elinks
30659
$ jobs -x mytest %elinks
args: 30659
$ pgrep mytest
31010
$ cat /proc/31010/cmdline 
/bin/bash /home/alex/bin/mytest 30659

$ nano
Use "fg" to return to nano.
[2]+  Stopped                 nano
$ pgrep nano
8930
$ jobs -x mytest %2
args: 8930
$ pgrep mytest
9010
$ cat /proc/9010/cmdline 
/bin/bash /home/alex/bin/mytest 8930

$ jobs -x kill %1
[1]-  Exit 2                  elinks
$ jobs -x kill -SIGKILL %2
[1]+  Killed                  nano
参考 http://mywiki.wooledge.org/BashGuide/JobControl
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
回复