在FiSH(友好交互式SHell)中,我可以在后台开始一个过程(something &
).但是,如果我尝试检索进程的进程ID(PID=$!
),我会收到来自fish的错误:
fish: Unknown command “PID=$!”. Did you mean “set PID $!”? For information on assigning values to variables, see the
help section on the set command by typing “help set”.
PID=$!: command not found
Run Code Online (Sandbox Code Playgroud)
如何检索后台进程的PID?
使用流程扩展,您可以编写
set PID %1 # if you know it's the first background job
set PID %something # if you know it's the only "something" running
Run Code Online (Sandbox Code Playgroud)
否则,我们可以使用该jobs
命令
set PID (jobs -l | awk '{print $2}') # just get the pid
jobs -l | read jobid pid cpu state cmd # get all the things
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2222 次 |
最近记录: |