How to get the PID of a process that is piped to another process in Bash?

前端 未结 14 1233
无人共我
无人共我 2020-12-01 01:35

I am trying to implement a simple log server in Bash. It should take a file as a parameter and serve it on a port with netcat.

( tail -f $1 & ) | nc -l -         


        
14条回答
  •  囚心锁ツ
    2020-12-01 02:26

    This works for me (SLES Linux):

    tail -F xxxx | tee -a yyyy &
    export TAIL_PID=`jobs -p`
    # export TEE_PID="$!"
    

    The ps|grep|kill trick mentioned in this thread would not work if a user can run the script for two "instances" on the same machine.

    jobs -x echo %1 did not work for me (man page not having the -x flag) but gave me the idea to try jobs -p.

提交回复
热议问题