blob: 46c6353143ec4f123b4beb30275b8e086f2b1961 (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
int main (int argc, char **argv) {
long maxsleep;
struct timespec ntime;
if (argc < 2) {
fputs("Usage: randsleep <max> [<cmd>]\n", stdout);
return 1;
}
maxsleep = atol(argv[1]);
if (clock_gettime(CLOCK_REALTIME, &ntime) == -1)
perror("clock_gettime");
srand(ntime.tv_nsec);
sleep((rand() % maxsleep) + 1);
if (argc > 2) {
execvp(argv[2], argv + 2);
perror("execvp");
}
return 0;
}
|