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

前端 未结 14 1222
无人共我
无人共我 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:35

    Not an ideal answer, but I found a workaround for a logger daemon I worked on:

    #!/bin/sh
    tail -f /etc/service/rt4/log/main/current --pid=$$ | grep error
    

    from $info tail:

    --pid=PID
              with -f, terminate after process ID, PID dies
    

提交回复
热议问题