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

标签 fish

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

相关文章:

shell - 有什么方法可以通过按组合键返回到 Fish shell 中准备输入的命令吗?

git - fish shell -eq 和 -a 在 if 语句中

shell - 在 fish shell 中压缩 for 循环(循环多个列表)

prompt - 在 Fish Shell 中获取当前目录(没有完整路径)

shell - 如何修复编辑已取消,shell 中未进行任何更改

intellij-idea - IntelliJ 的嵌入式终端不加载 fish 功能

linux - fish 编程: Why are `bind` commands in config. fish 没有执行?

string - 如何在 fish shell 中的字符串中有换行符?

bash - 无法通过 shellscript 激活 virtualenv

fish - 列出 Fish Tab-completion 中不同位置的目录