// syscall4.cpp
// Glenn G. Chappell
// 25 Jan 2012
//
// For CS 321 Spring 2012
// System calls demo #4
// Fork & write a bunch

#include <unistd.h>
// Used: fork, pid_t, write
#include <cstdlib>
using std::size_t;
#include <iostream>
using std::cout;
using std::endl;


int main()
{
    const int NUM_WRITES = 10000;
                   // Number of characters to write
    size_t dummy;  // For ignored return values

    cout << "Parent prints '#'" << endl;
    cout << "Child prints '.'" << endl;
    cout << endl;

    pid_t p = fork();
    if (p != 0) // Parent
    {
        for (int i = 0; i < NUM_WRITES; ++i)
            dummy = write(1, "#", 1);
    }
    else // p == 0; child
    {
        for (int i = 0; i < NUM_WRITES; ++i)
            dummy = write(1, ".", 1);
    }

    return 0;
}

