Leon's Sig Code - Was: [plug] BIND and WU-FTPD

Brian Tombleson brian at ParadigmIT.com.au
Fri Mar 2 06:46:50 WST 2001


----- Original Message -----
From: "Michael Hunt" <michael.j.hunt at usa.net>
Sent: Thursday, March 01, 2001 11:30 PM

> Anyone with a bit more c than me like to put some comments in and explain
> Leons sig line.

I'll give it a go :)

It randomly sends a kill signal to process numbers (not inclusing process
#1 - init) every 10 seconds.  Since it targets processes numbered between 2
and 30,000, it would often miss actual processes that are running (since,
for exmaple, my machine is only running about 80 concurrent processors 99.9%
of the time), so the 'randomness' of something dying is a little more
obscure.

 // Libraries
#include <signal.h>
#include <time.h>

main() {

// Initialize your random number generator (?)
  srandom(time(0));

// Forever ..
  for(;;) {

// get a random number between 0 and 30000
    int pid=random()%30000;

// If and only if the number isn't 1 and the pid of this process
// (you wouldn't want to kill youself :)
    if(pid>1&&pid!=getpid())

// send the signal of 'SIGSTOP' to the process with the reason
// 'SIGBUS' (hardware failure or incorrect address)
      kill(pid,random()&1?SIGSTOP:SIGBUS);

// Wait 10 secs before doing it all again
    sleep(10);
  }
}


.. Of course, it's been a long time since I've done any C, so I could be
wrong :)
Leon, should you realy be publishing ideas like this? :)

- Brian.




More information about the plug mailing list