| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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? |
|
#2
| |||
| |||
| 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 |
|
#3
| |||
| |||
| 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. |
|
#4
| |||
| |||
| 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/ |
|
#5
| |||
| |||
| 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. |
|
#6
| |||
| |||
| 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.... |
|
#7
| |||
| |||
| 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 |
|
#8
| |||
| |||
| 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. |
|
#9
| |||
| |||
| 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. |
|
#10
| |||
| |||
| 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. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.