Ejemplo n.º 1
0
int
main(
    int ac,
    char *av[]
) 
{
    if (ac != 6) {
    cerr << "Usage: "
    << av[0] 
    << " <sig> <pid> <max0> <max1> <max2> " 
    << endl;
    return 1;
    }

    signal(SIGUSR1, SIG_IGN);
    signal(SIGUSR2, die);

    int pid, sig;
    int max0 = atoi(av[3]);
    int max1 = atoi(av[4]);
    int max2 = atoi(av[5]);
    sig = atoi(av[1]);
    pid = atoi(av[2]);

    int category=0, t=0;
    while(1) {
    pid_t pp = getppid();
    if(pp == 1) { 
        cerr << "random_kick: parent went away -- exiting " << endl;
        return 1;
    }
      
    category = dorandom(3);

    switch(category) {
    case 0:
         t=dorandom(max0);
         break;
    case 1:
         t=dorandom(max1);
         break;
    case 2:
         t=dorandom(max2);
         break;
    }
    cout << "random_kick: pid " << getpid() << " sleep... " << t << endl;
    if(t>0) {
        sleep(t);
    }
    cout << "random_kick: kill " << pid << "," << sig << endl;
    kill(pid, sig);
    }
    return 0;
}
Ejemplo n.º 2
0
long random()
 {
 long val;
 mutex_lock(random_mutex);
 val=dorandom();
 mutex_unlock(random_mutex);
 return val;
 }
Ejemplo n.º 3
0
void srandom(x)
 {
 register long i;
 mutex_lock(random_mutex);
 state.state[0]=x;
 for(i=1;i!=DEG;++i) state.state[i]=(1103515145*state.state[i-1])+12345;
 state.fptr= &state.state[SEP];
 state.rptr= &state.state[0];
 for(i=0;i!=10*DEG;++i) dorandom();
 mutex_unlock(random_mutex);
 }