I need ideas on how to resume a stopped program...

This is a discussion on I need ideas on how to resume a stopped program... within the Programming Languages forums in category; Let's say that I have a program that downloads an unknown number of 2MB files from a remote server. Now after say the 500th file tranasfer, I want to stop the program via ctrl -c. Then say 6 hours later, I want to pick up where I left off. Ie, I want to start to download the 501st file. I clearly need to somehow save the state. What would be some sane methods?...

Go Back   Application Development Forum > Programming Languages

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-06-2008, 10:59 PM
Chad
Guest
 
Default I need ideas on how to resume a stopped program...

Let's say that I have a program that downloads an unknown number of
2MB files from a remote server. Now after say the 500th file
tranasfer, I want to stop the program via ctrl -c. Then say 6 hours
later, I want to pick up where I left off. Ie, I want to start to
download the 501st file.

I clearly need to somehow save the state. What would be some sane
methods?
Reply With Quote
  #2  
Old 09-06-2008, 11:14 PM
K-mart Cashier
Guest
 
Default Re: I need ideas on how to resume a stopped program...

On Sep 6, 7:59 pm, Chad <cdal...@gmail.com> wrote:
> Let's say that I have a program that downloads an unknown number of
> 2MB files from a remote server. Now after say the 500th file
> tranasfer, I want to stop the program via ctrl -c. Then say 6 hours
> later, I want to pick up where I left off. Ie, I want to start to
> download the 501st file.
>
> I clearly need to somehow save the state. What would be some sane
> methods?



I tried something like the following

[cdalten@localhost ~]$ more stop.c
#include <stdio.h>
#include <unistd.h>
#include <signal.h>

int main(void)
{

int i;

for (i = 0; i < 500; i++) {
printf("%d\n", i);
sleep(1);
}
return 0;
}
[cdalten@localhost ~]$ ./stop
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

[1]+ Stopped ./stop <---I issued kill -SIGTSTP <pid
number> from another screen
[cdalten@localhost ~]$ 21 I issued kill -SIGCONT <pid number> from
another screen
22
23
24
25
26
27
28
29
30
31
32

Reply With Quote
  #3  
Old 09-06-2008, 11:17 PM
Ian Collins
Guest
 
Default Re: I need ideas on how to resume a stopped program...

Chad wrote:
> Let's say that I have a program that downloads an unknown number of
> 2MB files from a remote server. Now after say the 500th file
> tranasfer, I want to stop the program via ctrl -c. Then say 6 hours
> later, I want to pick up where I left off. Ie, I want to start to
> download the 501st file.
>
> I clearly need to somehow save the state. What would be some sane
> methods?


Don't kill it with control C, suspend it with control Z.

--
Ian Collins.
Reply With Quote
  #4  
Old 09-07-2008, 01:47 AM
John Tsiombikas
Guest
 
Default Re: I need ideas on how to resume a stopped program...

On 2008-09-07, Ian Collins <ian-news@hotmail.com> wrote:
>
> Chad wrote:
>> Let's say that I have a program that downloads an unknown number of
>> 2MB files from a remote server. Now after say the 500th file
>> tranasfer, I want to stop the program via ctrl -c. Then say 6 hours
>> later, I want to pick up where I left off. Ie, I want to start to
>> download the 501st file.
>>
>> I clearly need to somehow save the state. What would be some sane
>> methods?

>
> Don't kill it with control C, suspend it with control Z.
>


Right, and of course 6 hours later, the socket will still be connected
to the server

--
John Tsiombikas (Nuclear / Mindlapse)
http://nuclear.sdf-eu.org/
Reply With Quote
  #5  
Old 09-07-2008, 02:22 AM
Rainer Weikusat
Guest
 
Default Re: I need ideas on how to resume a stopped program...

John Tsiombikas <nuclear@siggraph.org> writes:
> On 2008-09-07, Ian Collins <ian-news@hotmail.com> wrote:
>>> Let's say that I have a program that downloads an unknown number of
>>> 2MB files from a remote server. Now after say the 500th file
>>> tranasfer, I want to stop the program via ctrl -c. Then say 6 hours
>>> later, I want to pick up where I left off. Ie, I want to start to
>>> download the 501st file.
>>>
>>> I clearly need to somehow save the state. What would be some sane
>>> methods?

>>
>> Don't kill it with control C, suspend it with control Z.
>>

>
> Right, and of course 6 hours later, the socket will still be connected
> to the server


The socket itself will not change its state. But the server will
likely close the connection in the meantime.
Reply With Quote
  #6  
Old 09-07-2008, 04:08 AM
James Harris
Guest
 
Default Re: I need ideas on how to resume a stopped program...

On 7 Sep, 06:47, John Tsiombikas <nucl...@siggraph.org> wrote:
> On 2008-09-07, Ian Collins <ian-n...@hotmail.com> wrote:
>
>
>
> > Chad wrote:
> >> Let's say that I have a program that downloads an unknown number of
> >> 2MB files from a remote server. Now after say the 500th file
> >> tranasfer, I want to stop the program via ctrl -c. Then say 6 hours
> >> later, I want to pick up where I left off. Ie, I want to start to
> >> download the 501st file.

>
> >> I clearly need to somehow save the state. What would be some sane
> >> methods?

>
> > Don't kill it with control C, suspend it with control Z.

>
> Right, and of course 6 hours later, the socket will still be connected
> to the server


Not as it stands, but if the program's response to I/O errors is to
rebuild the connection and retry....
Reply With Quote
  #7  
Old 09-07-2008, 04:16 AM
James Harris
Guest
 
Default Re: I need ideas on how to resume a stopped program...

On 7 Sep, 03:59, Chad <cdal...@gmail.com> wrote:
> Let's say that I have a program that downloads an unknown number of
> 2MB files from a remote server. Now after say the 500th file
> tranasfer, I want to stop the program via ctrl -c. Then say 6 hours
> later, I want to pick up where I left off. Ie, I want to start to
> download the 501st file.
>
> I clearly need to somehow save the state. What would be some sane
> methods?


I'll assume you are writing the program (rather than just using it).
Given what you say, after each file completed you could write a
checkpoint record to your local disk saying which file has been
successfully downloaded. Then, when you restart the program just read
this record and carry on from where you left off.

You may want to write other checkpoint data at the same time such as
the date so that if the next run of your program is a number of days
after the last one it knows to start again rather than going back to
where it stopped. It depends on your requirements.

Also you may want to write two checkpoint files - updating them
alternately (i.e. always updating the older one) - so that if the
machine should crash while writing one checkpoint file you would still
have a valid file (i.e. the other one) from which to resume.

--
HTH,
James
Reply With Quote
  #8  
Old 09-07-2008, 04:18 AM
CBFalconer
Guest
 
Default Re: I need ideas on how to resume a stopped program...

Chad wrote:
>
> Let's say that I have a program that downloads an unknown number
> of 2MB files from a remote server. Now after say the 500th file
> tranasfer, I want to stop the program via ctrl -c. Then say 6
> hours later, I want to pick up where I left off. Ie, I want to
> start to download the 501st file.
>
> I clearly need to somehow save the state. What would be some
> sane methods?


Write the state to a known file. If complete, delete the state
file. At start time, start from the command line if no state file
exists, else after the last event in the state file.

All you really need to ensure is that the state file name is
unique.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Reply With Quote
  #9  
Old 09-07-2008, 07:35 AM
Ben Bacarisse
Guest
 
Default Re: I need ideas on how to resume a stopped program...

Chad <cdalten@gmail.com> writes:

> Let's say that I have a program that downloads an unknown number of
> 2MB files from a remote server. Now after say the 500th file
> tranasfer, I want to stop the program via ctrl -c. Then say 6 hours
> later, I want to pick up where I left off. Ie, I want to start to
> download the 501st file.
>
> I clearly need to somehow save the state. What would be some sane
> methods?


Are you lucky enough that the files themselves represent the state you
need? I can imagine a case where you can tell from the names or times
which is the last file that was being fetched. On restart, you could
either always re-pull the last file or, if there is a way to tell that
it is complete, you could avoid fetching it unnecessarily in those few
cases where you stop after a complete fetch bit before there is any
evidence of a newer incomplete one.

--
Ben.
Reply With Quote
  #10  
Old 09-07-2008, 09:54 AM
K-mart Cashier
Guest
 
Default Re: I need ideas on how to resume a stopped program...

On Sep 7, 4:35 am, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> Chad <cdal...@gmail.com> writes:
> > Let's say that I have a program that downloads an unknown number of
> > 2MB files from a remote server. Now after say the 500th file
> > tranasfer, I want to stop the program via ctrl -c. Then say 6 hours
> > later, I want to pick up where I left off. Ie, I want to start to
> > download the 501st file.

>
> > I clearly need to somehow save the state. What would be some sane
> > methods?

>
> Are you lucky enough that the files themselves represent the state you
> need? I can imagine a case where you can tell from the names or times
> which is the last file that was being fetched. On restart, you could
> either always re-pull the last file or, if there is a way to tell that
> it is complete, you could avoid fetching it unnecessarily in those few
> cases where you stop after a complete fetch bit before there is any
> evidence of a newer incomplete one.
>
> --


The file themselves don't represent the state that I need.

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:55 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.