在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
如何获取后台进程的PID?
最佳答案
使用process expansion,您可以编写
set PID %1 # if you know it's the first background job
set PID %something # if you know it's the only "something" running
请注意,此功能是removed in fish version 3。
否则,我们可以使用
jobs
命令set PID (jobs -l | awk '{print $2}') # just get the pid
jobs -l | read jobid pid cpu state cmd # get all the things
关于 fish shell 如何在后台启动进程的PID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30379934/