farm - err(1, "fork"); case 0: /*...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * farm.c * * Run a bunch of cpu pigs and one cat. * The file it cats is "catfile". This should be created in advance. * * This test should itself run correctly when the basic system calls * are complete. It may be helpful for scheduler performance analysis. */ #include <unistd.h> #include <err.h> static char *hargv[2] = { (char *)"hog", NULL }; static char *cargv[3] = { (char *)"cat", (char *)"catfile", NULL }; #define MAXPROCS 6 static int pids[MAXPROCS], npids; static void spawnv(const char *prog, char **argv) { int pid = fork(); switch (pid) { case -1:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: err(1, &quot;fork&quot;); case 0: /* child */ execv(prog, argv); err(1, &quot;%s&quot;, prog); default: /* parent */ pids[npids++] = pid; break; } } static void waitall(void) { int i, status; for (i=0; i&lt;npids; i++) { if (waitpid(pids[i], &amp;status, 0)&lt;0) { warn(&quot;waitpid for %d&quot;, pids[i]); } else if (status != 0) { warnx(&quot;pid %d: exit %d&quot;, pids[i], status); } } } static void hog(void) { spawnv(&quot;/testbin/hog&quot;, hargv); } static void cat(void) { spawnv(&quot;/bin/cat&quot;, cargv); } int main() { hog(); hog(); hog(); cat(); waitall(); return 0; }...
View Full Document

This note was uploaded on 11/10/2009 for the course CS 536 taught by Professor Lums during the Spring '09 term at Indiana.

Page1 / 2

farm - err(1, &amp;amp;quot;fork&amp;amp;quot;); case 0: /*...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online