On Fri, Jul 15, 2011 at 2:29 PM, Anupam Jain <ajn...@gmail.com> wrote:

> Hi all,
>
> I originally posted this question on
> stackoverflow<
> http://stackoverflow.com/questions/6624622/what-happens-in-bash-when-you-do-ctrl-c-hint-its-not-simply-sending-a-sigint
> >,
> but did not receive a satisfactory response. Any ideas?
>
> --------------8<-----------------
>
> A little background first - When I do apt-get install downloads from my
> company internet it provides a high burst of speed (400-500KB/s) for the
> first 10 seconds or so before dropping down to a tenth of that (40-50KB/s),
> and then after a few minutes to a truly miserable (4-5KB/s). This makes me
> think that the sysadmin has implemented some sort of a network throttling
> scheme.
>
> Now I know that the network is not simply erratic, because if I start
> an apt-get
> install foo, Ctrl-C it after 10 seconds and immediately run apt-get install
> foo again (by doing an up arrow and enter to use bash history), and then
> *keep
> repeating this process for a few minutes till all packages are downloaded*,
> I can download even large packages very fast. In particular, even after
> aborting a download with Ctrl-C, apt-get seems to be able to resume the
> download in the next invocation.
>
> Of course, staring at the screen doing Ctrl-C Up Enter every 10 seconds
> gets
> really boring real fast, so I wrote a shell script -
>
> #!/bin/sh
>
> for i in `seq 1 100` ; do
>
>
>    sudo apt-get install foo -y &
>
>
>    sleep 10
>
>
>    sudo kill -2 $!
>
> done
>
>  This seems to work. It spawns apt-get, runs it for 10 seconds and then
> kills (by sending a SIGINT) it and starts it up again. However, it doesn't
> really work because now apt-get does not resume downloads on subsequent
> invocations!
>
> An an experiment I ran sudo apt-get install foo from one terminal and then
> ran kill -2 <PID of apt-get> from another terminal. And even in that case,
> when I restart apt-get, it does not resume the download.
>
> So clearly a Ctrl-C is *not* equivalent to SIGINT. And something else is
> happening when I do Ctrl-C manually which gives apt-get a chance to save
> the
> state of the download. The question is - what is it?
> These are the suggestions I have received so far, but no cigars. The
> mystery
> deepens! -
>
>   1.
>
>   On sudo kill -2 $! the signal might be going to sudo instead of apt-get.
>   This is not the reason because as mentioned above I also tried sending
>   SIGINT specifically to apt-get's PID and even that prevented apt-get from
>   saving its state.
>   2.
>
>   Sudo catches the signal and sends some other signal to apt-get. I tried
>   sending apt-get all the signals I can think of! It still does not resume
> the
>   download for any of them. It only resumes downloads when I do Ctrl-C to
> kill
>   it.
>   3.
>
>   Apt-get handles SIGINT differently if it is from a script instead of an
>   interactive shell. Again, the "experiment" above proves that this is not
>   true.
>
>
> ------------------>8-----------------
>

Heard of signal handlers? SIGINT (Ctrl-C) is trapped by libdpkg, which then
performs cleanup and saves index state before exiting. apt-get is only a
frontend for dpkg.

http://osdir.com/ml/debian-dpkg-cvs/2011-01/msg00129.html

Whether or not your downloads resume from last interrupted state depends on
several factors, for example the size of package (if it's too small, it may
be kept in tmpfs instead of /var/cache/apt/archive), or if the remote
timestamp/checksum changes, or server may not  support http-resume method
for binaries, or if it's a source download; from man:

Note that source packages are not tracked like
binary packages, they exist only in the current
directory and are similar to downloading source tar
balls.


> Thanks,
> Anupam Jain
> _______________________________________________
> Ilugd mailing list
> Ilugd@lists.linux-delhi.org
> http://frodo.hserus.net/mailman/listinfo/ilugd
>



-- 
-- 
Ankit Chaturvedi
GPG: 05DE FDC5 468B 7D9F 9F45 72F1 F7B9 9E16 ECA2 CC23
<http://www.google.com/profiles/ankit.chaturvedi>
_______________________________________________
Ilugd mailing list
Ilugd@lists.linux-delhi.org
http://frodo.hserus.net/mailman/listinfo/ilugd

Reply via email to