Skip to content

Instantly share code, notes, and snippets.

@tanakamura
Created September 3, 2016 06:18
Show Gist options
  • Save tanakamura/e288eb4d9a324a7c2678a010c5cdf131 to your computer and use it in GitHub Desktop.
Save tanakamura/e288eb4d9a324a7c2678a010c5cdf131 to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <time.h>
#include <stdio.h>
double sec(void) {
struct timespec tv;
clock_gettime(CLOCK_MONOTONIC, &tv);
return tv.tv_sec + tv.tv_nsec / (1000000000.0);
}
int main()
{
int nloop = 1024, li;
double t0 = sec(), t1;
for (li=0; li<nloop; li++) {
int pid = fork();
int st;
if (pid == 0) {
execlp("./exit2",
"./exit2",
NULL);
}
wait (&st);
}
t1 = sec();
printf("%f\n", (t1-t0)/nloop);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment