midedup_p - loop(); cout << "p" << k...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// mixedup_p.cpp / #include <unistd.h> #include <time.h> #include <stdio.h> #include <iostream.h> #include <stdlib.h> # void loop() { sleep(rand()%5); } void parent(long childPID, int k) { cout << "Parent process: pid " << getpid() << ", ppid " << getppid() << ", child " << childPID << endl; srand((unsigned) time((time_t *) NULL)); for (int i=0; i<10; ++i) {
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: loop(); cout << "p" << k << ":" << i << " "; } cout << endl; } int main() { i long childPID1; long childPID2; setbuf(stdout, NULL); if (childPID1 = fork()) parent(childPID1, 1); else if (childPID2 = fork()) parent(childPID2, 2); else { execl("./mixedup_c", "mixedup_c", (char*)0); exit(0); } exit(0); }...
View Full Document

This note was uploaded on 04/11/2010 for the course CECS 326 taught by Professor Staff during the Spring '08 term at CSU Long Beach.

Ask a homework question - tutors are online