I've recently set up some torrents on my home Linux PC, mainly for Debian and Knoppix distros. I'm quite into the idea of using my spare bandwidth to seed torrents for others, but I find that this chews up my upload potential to the detrement of other things I'm doing.

I'm using the shell to background a number of btdownloadgui processes - these each provide a visual indication of the status of a given torrent. I could click "close" on all of the GUIs whenever I want to use my bandwidth for something else. But, I've found a neater solution.

There's a pair of signals: SIGSTOP and SIGCONT that can be used to suspend and resume processes. On i386 Debian, these signals are 19 and 18 respectively; see "man 7 signal" for the list of signal numbers that apply to your platform.

The shell (bash in this case) doesn't easily provide lists of PIDs. If there's exactly one process running a given command, you can use %string as a job specifier to find the PID, provided it is a child process of your current shell. As an alternative, here is some perl that will give you a list of matching PIDs to STDOUT:

#!/usr/bin/perl # findpids use strict; use warnings; use Unix::PID; use Getopt::Long; my $cmd = ''; GetOptions( 'command=s' => \$cmd, ); my $pobj = Unix::PID->new; print join(' ',$pobj->get_pidof($cmd)),"\n";

Now, I can easily suspend and resume all my torrent processes, voila:

ivor@orinoco:~$ kill -19 `findpids --command btdownloadgui` ivor@orinoco:~$ jobs [1] Stopped nice btdownloadgui --saveas ${fil%.torre +nt} $torrent (wd: ~) [2]+ Stopped nice btdownloadgui --saveas ${fil%.torre +nt} $torrent (wd: ~) [3] Stopped nice btdownloadgui --saveas ${fil%.torre +nt} $torrent (wd: ~) [5] Stopped nice btdownloadgui --saveas ${fil%.torre +nt} $torrent (wd: ~) [6] Stopped nice btdownloadgui --saveas ${fil%.torre +nt} $torrent (wd: ~) [7] Stopped nice btdownloadgui --saveas ${fil%.torre +nt} $torrent (wd: ~) [8] Stopped nice btdownloadgui --saveas ${fil%.torre +nt} $torrent (wd: ~) [9]- Stopped nice btdownloadgui --saveas ${fil%.torre +nt} $torrent (wd: ~)

The torrents die down and I get to use the bandwidth. Then, when I've finished:

ivor@orinoco:~$ kill -18 `findpids --command btdownloadgui`

and the lights start flickering on my router again.

--

Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ?
(Missquoting Janis Joplin)

Replies are listed 'Best First'.
Re: Managing BitTorrent traffic
by jasonk (Parson) on Aug 12, 2006 at 18:39 UTC
    % killall -STOP btdownloadgui % killall -CONT btdownloadgui

    We're not surrounded, we're in a target-rich environment!
Re: Managing BitTorrent traffic
by polettix (Vicar) on Aug 13, 2006 at 16:40 UTC
    You can ask the list of signals directly to kill:
    poletti@PolettiX:~$ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 33) SIGRTMIN 34) SIGRTMIN+1 35) SIGRTMIN+2 36) SIGRTMIN+3 37) SIGRTMIN+4 38) SIGRTMIN+5 39) SIGRTMIN+6 40) SIGRTMIN+7 41) SIGRTMIN+8 42) SIGRTMIN+9 43) SIGRTMIN+10 44) SIGRTMIN+11 45) SIGRTMIN+12 46) SIGRTMIN+13 47) SIGRTMIN+14 48) SIGRTMIN+15 49) SIGRTMAX-15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX
    Moreover, as jasonk suggested, you can also use the symbolic name instead of the signal number (just throw away the 'SIG' part).

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.