gpt4 book ai didi

fish shell 如何在后台启动进程的PID

转载 作者:行者123 更新时间:2023-12-04 04:04:47 24 4
gpt4 key购买 nike

在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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com