Created
January 6, 2017 14:25
-
-
Save aib/18f5c9d29114be61698f4248a6df1489 to your computer and use it in GitHub Desktop.
stagger test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <time.h> | |
#define PROCS 10 | |
int child(int n) | |
{ | |
while (1) { | |
time_t tt; | |
time(&tt); | |
struct tm *tmi = localtime(&tt); | |
char buffer[64]; | |
strftime(buffer, sizeof(buffer), "%FT%T", tmi); | |
printf("%d %s\n", n, buffer); | |
fflush(stdout); | |
for (volatile unsigned long k=0; k<10000; ++k) | |
for (volatile unsigned long j=0; j<1000; ++j) | |
for (volatile unsigned long i=0; i<1000; ++i); | |
sleep(10); | |
} | |
} | |
int main(void) | |
{ | |
for (int i=0; i<PROCS; ++i) { | |
pid_t pid = fork(); | |
if (pid == 0) { | |
return child(i); | |
} | |
} | |
while (1) { | |
sleep(1); | |
} | |
} | |
/* | |
$ gcc -Wall -std=gnu11 hmm.c && ./a.out | tee hmm.txt | |
$ gnuplot <<EOF >hmm.png | |
set terminal png size 960,540 | |
set xdata time | |
set timefmt "%Y-%m-%dT%H:%M:%S" | |
plot "hmm.txt" using 2:(1) with points | |
EOF | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment