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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |