/*
 Parent and child processes demo

 Run this several times: first, as given
                         then, change HOW_MANY to 100000
 */

#include <stdio.h>
#include <unistd.h>

#define HOW_MANY 10

void generateOutput(int n, char ch);

int main() {
    pid_t pid;

    /* fork a child process */
    pid = fork();

    if (pid == 0) {
	/* child process */
	generateOutput(HOW_MANY, 'C');
    }
    else {
	/* parent process */
	generateOutput(HOW_MANY, 'P');
    }
    printf("\n");
    return 0;
}

void generateOutput(int n, char ch) {
    /* Output a stream of n characters */
    int i;
    for (i = 0; i < n; i++)
	printf("%c", ch);
}
