How to display time elapsed continuously while a lengthy task is running?

On Linux I run a C++ program that invokes 3 tasks one by one like this:

int main()
{
task1();
task2();
task3();
return 0;
}

Each task may take about 5 minutes to complete. When a task is running, Log messages will be displayed on screen one by one.

What I'm looking for is a way to continuously display the time elapsed (in seconds) at the bottom of the screen (use one line at the bottom) when a task is running.

I would appreciate it if some one could help. A sample code would be very helpful.

Thanks!
Last edited on
You will need to use threading, I think.

Is this a GUI or CLI application?
This is a CLI application.

I agree I need to use another thread to display the elapsed time. What I'm not sure are:

- How to make the new thread work with the main thread (i.e. main())
- How to print out only one line at the bottom of screen to display the elapsed time while take1() keeps popping up log messages to screen. It doesn't look good if the application displays multiple lines for showing the elapsed time

Thanks.
You could make another executable to have another terminal. I'm fairly sure it'll be one process, one window, unless you used Gtk or something. The only non-Windows GUI I've done was Python-Tkinter.
Thanks for the suggestions.
Topic archived. No new replies allowed.