I have done a computation using CUDA and it takes around 12 minutes to complete the whole computation. I am using this command in a .sh file to run the program:

CUDA_VISIBLE_DEVICES=0 ./a1.out | tee -a output.txt &
CUDA_VISIBLE_DEVICES=1 ./a2.out | tee -a output.txt &
CUDA_VISIBLE_DEVICES=2 ./a3.out | tee -a output.txt &
CUDA_VISIBLE_DEVICES=3 ./a4.out | tee -a output.txt &
CUDA_VISIBLE_DEVICES=4 ./a5.out | tee -a output.txt &
CUDA_VISIBLE_DEVICES=5 ./a6.out | tee -a output.txt &

Now I want to show a progress bar for this process in the command line window for user. Is there is any way to do it?

  • Where would the progress information come from?
    – muru
    Jul 12, 2017 at 4:40
  • I am expecting if there is some command which can tell me the progress of executable file directly. Otherwise I am taking total of 1000 values into the file output.txt. Maybe it can help in showing progress bar..
    – agangwal
    Jul 12, 2017 at 4:57
  • Using what? Magic?
    – muru
    Jul 12, 2017 at 4:58
  • I am taking total of 1000 values into the file output.txt. Maybe it can help in showing progress bar..but I don't know how to do it.
    – agangwal
    Jul 12, 2017 at 4:59
  • There is a for loop of 1000 iterations in my code which prints 1000 values in output.txt. Please tell me how can I use this to show progress bar??
    – agangwal
    Jul 12, 2017 at 5:02

1 Answer 1


Use pv(1) in line mode:

COMMAND | pv --line-mode --size 1000 >> output.txt

or shorter

COMMAND | pv -ls 1000 >> output.txt

-s/--size sets the number of expected output units (bytes by default or lines in line mode).

If you want to capture the output and display the progress of multiple commands running in parallel you can do so with a compound statement:

{ COMMAND1 & COMMAND2 & COMMAND3; } | pv -ls 1000 >> output.txt

In that case you need to specify the number of expected output units of all commands in total.


for i in {1..200}; do sleep 0.1; echo "$i"; done | pv -ls 200 > /dev/null
  • This is a good example. But it didn't work with my command. I think it works only when you print output in text file through shell script. Here my code is written in CUDA language and a.out is an executable file and I am printing output of this file into a text file. Do you have any solution for this situation??
    – agangwal
    Jul 13, 2017 at 4:34
  • @agangwal: Could you please edit your question to include what exactly you did and what happened? If the example in your question works, that means the programs are writing their output to the standard output file descriptor which can be piped into a different program like tee or pv. It also doesn't matter whether the source end of the pipe is a custom-written program or a shell script since both produce a sequence of bytes and write it to a file descriptor. Jul 13, 2017 at 8:44
  • I get it now. I was not printing my output to stdout. I was printing it in a file which causes problem to use pv command.
    – agangwal
    Jul 13, 2017 at 8:59

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.