gpt4 book ai didi

linux - 在 sh 脚本中,获取后台进程的 pid

转载 作者:可可西里 更新时间:2023-11-01 11:44:46 25 4
gpt4 key购买 nike

是否可以在以下bash脚本中知道iwevent进程的pid:

#!/bin/sh
( iwevent | logger -t IWEVENT ) &
echo the pid is: ???

注意 iwevent 运行直到 ctrl-c 信号。

仅供引用。我在/etc/network/interfaces "up"语句中运行这个脚本,我想在相关的 "down"语句中终止正在运行的 iwevent 进程。我的目标是记录无线事件。

最佳答案

像这样的东西应该可以解决问题:

#!/bin/sh
( { iwevent & printf "The pid is %s\n" $! >&3; } | logger -t IWEVENT ) 3>&1 &

如果您需要在变量中使用它,请阅读上面的输出。

关于linux - 在 sh 脚本中,获取后台进程的 pid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3891963/

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