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 – Rui F Ribeiro Jan 13 '18 at 13:06
  • I have more than one pv process. Thats why I want to take when i started. – Morphinz Jan 13 '18 at 13:13
  • ps -eaf | grep -i scriptname| awk '{print $2}|head -1 – Praveen Kumar BS Jan 13 '18 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 '18 at 13:23

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.