1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| /* transmitter.c */
#include "sigarray.h"
#include <errno.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
int main(int argc, char *argv[])
{
long int pid;
if (argc < 2)
{
fprintf(stderr, "Not enough command-line arguments\n");
return EXIT_FAILURE;
}
errno = 0;
pid = strtol(argv[1], NULL, 10);
if ((pid == LONG_MIN || pid == LONG_MAX) && errno != 0)
{
perror("strtol");
return EXIT_FAILURE;
}
srand(time(NULL));
for (;;)
{
int signum = sigarray[rand() % sigsize];
printf("#%d: Send next signal? ", (int)getpid());
getchar();
if (kill((pid_t)pid, signum) == -1)
{
perror("kill");
return EXIT_FAILURE;
}
printf("#%d Signal %d sent\n", (int)getpid(), signum);
}
return EXIT_SUCCESS;
} |
Partager