forktest

forktest - /* * forktest - test fork(). * * This should...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: /* * forktest - test fork(). * * This should work correctly when fork is implemented. * * It should also continue to work after subsequent assignments, most * notably after implementing the virtual memory system. */ #include <unistd.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <err.h> /* * This is used by all processes, to try to help make sure all * processes have a distinct address space. */ static volatile int mypid; /* * Helper function for fork that prints a warning on error. */ static int dofork(void) { int pid; pid = fork(); if (pid < 0) { warn("fork"); } return pid; } /* * Check to make sure each process has its own address space. Write * the pid into the data segment and read it back repeatedly, making * sure it's correct every time. */ static void check(void) { int i; mypid = getpid(); /* Make sure each fork has its own address space. */ for (i=0; i<800; i++) { volatile int seenpid; seenpid = mypid; if (seenpid != getpid()) { errx(1, "pid mismatch (%d, should be %d) " "- your vm is broken!", seenpid, getpid()); } } }...
View Full Document

Page1 / 3

forktest - /* * forktest - test fork(). * * This should...

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