summaryrefslogtreecommitdiff
path: root/src/randsleep.c
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-07-06 22:16:47 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-07-06 22:16:47 +0200
commitdaac5c780296fbbf1005fedb45ae790d567b2dcd (patch)
tree6620d4c46fd5107a95e6ec7a65ad0524a650ae3d /src/randsleep.c
Initial commit
Diffstat (limited to 'src/randsleep.c')
-rw-r--r--src/randsleep.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/randsleep.c b/src/randsleep.c
new file mode 100644
index 0000000..d06fb0a
--- /dev/null
+++ b/src/randsleep.c
@@ -0,0 +1,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>", 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");
+}