summaryrefslogtreecommitdiff
path: root/src/randsleep.c
blob: 389e3a7da75ec2e7bbc948855ff031ff7fc0ac53 (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
#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);

	execvp(argv[2], argv + 2);
	perror("execvp");
}