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)


In reply to Managing BitTorrent traffic by rinceWind

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.