|  | I need ideas on how to resume a stopped program... |  | |
| | | Chad |  |
| Posted: Sun Sep 07, 2008 2:59 am Post subject: 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? |
| |
| | | Ian Collins |  |
| Posted: Sun Sep 07, 2008 2:59 am Post subject: Re: I need ideas on how to resume a stopped program... |  |
Chad wrote:
| Quote: | 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. |
| |
| | | K-mart Cashier |  |
| Posted: Sun Sep 07, 2008 3:14 am Post subject: Re: I need ideas on how to resume a stopped program... |  |
On Sep 6, 7:59 pm, Chad <cdal...@gmail.com> wrote:
| Quote: | 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 |
| |
| | | Rainer Weikusat |  |
| Posted: Sun Sep 07, 2008 4:22 am Post subject: Re: I need ideas on how to resume a stopped program... |  |
John Tsiombikas <nuclear@siggraph.org> writes:
| Quote: | 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. |
| |
| | | Richard Heathfield |  |
| Posted: Sun Sep 07, 2008 5:27 am Post subject: Re: I need ideas on how to resume a stopped program... |  |
Chad said:
| Quote: | 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?
|
In comp.programming, the answer is "checkpointing". This page has some useful links: LINK
I don't know what the comp.unix.programmer answer is.
-- Richard Heathfield <http://www.cpax.org.uk> Email: -http://www. +rjh@ Google users: <http://www.cpax.org.uk/prg/writings/googly.php> "Usenet is a strange place" - dmr 29 July 1999 |
| |
| | | John Tsiombikas |  |
| Posted: Sun Sep 07, 2008 5:47 am Post subject: Re: I need ideas on how to resume a stopped program... |  |
On 2008-09-07, Ian Collins <ian-news@hotmail.com> wrote:
| Quote: | 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) LINK |
| |
| | | CBFalconer |  |
| Posted: Sun Sep 07, 2008 6:18 am Post subject: Re: I need ideas on how to resume a stopped program... |  |
Chad wrote:
| Quote: | 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. |
| |
| | | James Harris |  |
| Posted: Sun Sep 07, 2008 8:08 am Post subject: Re: I need ideas on how to resume a stopped program... |  |
On 7 Sep, 06:47, John Tsiombikas <nucl...@siggraph.org> wrote:
| Quote: | 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.... |
| |
| | | James Harris |  |
| Posted: Sun Sep 07, 2008 8:16 am Post subject: Re: I need ideas on how to resume a stopped program... |  |
| |  | |
On 7 Sep, 03:59, Chad <cdal...@gmail.com> wrote:
| Quote: | 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 |
| |
| | | Ben Bacarisse |  |
| Posted: Sun Sep 07, 2008 9:35 am Post subject: Re: I need ideas on how to resume a stopped program... |  |
Chad <cdalten@gmail.com> writes:
| Quote: | 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. |
| |
| Page 1 of 2 .:. Goto page 1, 2 Next | |
|
|