[英]How to know two process ids in “tail -f filename.dat | nc localhost 36000 &”
As described in the title, I want to know the process id of tail
and nc
. 如标题中所述,我想知道
tail
和nc
的进程ID。
It is easy to use $!
易于使用
$!
to get the pid of nc
, but how about tail
? 获取
nc
的pid,但是tail
呢?
From comments - you're wanting to terminate these processes once a separate event occurs. 从注释开始-您希望在发生单独的事件后终止这些过程。
Try a subshell. 尝试一个子shell。 (
cat -v
in the below for my testing) (下面的
cat -v
用于我的测试)
eg 例如
( tail -f /path_to_file/ | cat -v ) & echo $!
This will give you a pid of a spawned subshell, which you can kill and get your sub processes at the same time. 这将为您提供一个生成的子外壳的pid,您可以同时杀死它并获取子进程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.