I'm running bash files for zfs send jobs and this my bash file example:

zfs send -Rc tank/test@snap | pv -fs datasize -F "%p***%t***%e***%r***%b" |
  mbuffer -q -s 128k -m 1G -O ip:port

When I start the bash I want to know PV pid. I couldn't figure out how can I take pv pid.

  • use the command pgrep pv Jan 13, 2018 at 13:06
  • I have more than one pv process. Thats why I want to take when i started.
    – Morphinz
    Jan 13, 2018 at 13:13
  • ps -eaf | grep -i scriptname| awk '{print $2}|head -1 Jan 13, 2018 at 13:18
  • @PraveenKumarBS Its only gives me my bash pid. I want to take PV pid. My script as you can see creates 4 different pid in same time. 1=bash pid, 2=zfs pid, 3=pv pid, 4=mbuffer pid. I need to catch PV.
    – Morphinz
    Jan 13, 2018 at 13:23

1 Answer 1


Pipe viewer has an option for this job. You can save pid to a file with this command.

-P FILE, --pidfile FILE Save the process ID of pv in FILE. The file will be truncated if it already exists, and will be removed when pv exits. While pv is running, it will contain a single number - the process ID of pv - followed by a newline.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .