[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Predict programme finish time

Posted on 2011-02-14
Medium Priority
Last Modified: 2012-08-13
Hi *,

I have some programs which run for a long time; sometimes they run for days/weeks. I can calculate how far through a programme is in percent. What I would like to do is predict (roughly, assuming the programme speed is linear) when a programme should finish.

I have thought that this should be possible by recording the date and time when the programme starts, and then using the current percentage to predict forwards. What I would like is to be able to display a string, containing an estimated time left; perhaps like this:
w0 d13 h17 m22

One thing is that, I currently (due to computer setup) I have another programme displaying the current progress of a programme. Therefore, I have a programme (which I want to monitor and predict finish time for) saving the current progress to a file. This file is then read by the other programme and displays the progress to the user. Therefore, the start time would need to be saved to this same text file and read by the other programme.

Any suggestions? Thoughts?

Question by:James_h1023
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 53

Accepted Solution

Infinity08 earned 2000 total points
ID: 34888027
If you have the start time, and the percentage of progress, then you can calculate the end time :

        end_time = start_time + ((current_time - start_time) / percentage)

where all times are in seconds since the epoch (or something similar), and percentage is a value between 0 and 1.

Author Comment

ID: 34888189
Thanks for your response.

This is true, I had completely forgotton that one can get the seconds since the epoch in Unix.

Very simply question!

LVL 53

Expert Comment

ID: 34888381
Btw, be careful for division by 0 ;)
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 34888462
In fact, I say it was simple, but I am having a nightmare implementing it!

I am getting all stuck up in variables types.

I have the attached.

I'm looking at the lines with lots of 'X's. I think I currently have problems with casting between floats and ints, as end up with -2010200302 or something similar for predTime.

Also, how could I convert from int (assuming it is calcaulted properly, i.e., predTime) back to time_t which ctime() needs so I can output the time as a nice string.

Sorry, I close the question too early. Nevermind, if it is too late.

// Get the current progress
float progress=0.23;

// Get the start time in seconds
char *progressC[100];
int  progressD=0;
FILE *f1;
f1 = fopen("progress.dat", "rt");
fgets(progressC, 100, f1);
progressD = atoi(progressC);

// Get the current time in seconds
time_t tim=time(NULL);

// Predict end time in seconds
printf("%s\n", predTimeC);

Open in new window

LVL 53

Expert Comment

ID: 34888784
>> Sorry, I close the question too early. Nevermind, if it is too late.

It's certainly not too late. As long as it has to do with the original question (which is definitely the case here), I'm always ready to provide additional support.

>> char *progressC[100];

You probably want :

        char progressC[100] = "";

(similarly for predTimeC further in the code)

>> progressD = atoi(progressC);

Representating the time in seconds since the epoch, can be a large value that might not fit in a (signed) int.
It's probably best to use a time_t, and to store it in binary form in the file.

predTime could then be calculated something like this (assuming that time_t is an integer value that represents the number of seconds since the epoch on your specific platform - which is the case for the large majority of platforms these days) :

        time_t predTime = progressD + ((tim - progressD) / progress);

(I would pick more meaningful/consistent variable names though - see my first post eg.)

Note that this will NOT work on platforms where time_t is NOT an integer value that represents the number of seconds since the epoch on your specific platform. But as said : that is quite unlikely.
LVL 53

Expert Comment

ID: 34888794
Oh, and you can format a time_t as a string using strftime :


(see the code example at the bottom of that reference page)

Author Comment

ID: 34889959
Wonderful, that's got my silly questions answered.

Many thanks,

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question