/* * example.c * * Created on: Sep 7, 2018 * Author: cs3841 */ #include #include #include #include #include static void capitalize(); static void interact(); int main(int argc, char* argv[]) { int pid = getpid(); printf("pid: %d\n",pid); // Create the pipe BEFORE forking so both processes get a copy int pipe_to_child[2]; int pipe_to_parent[2]; pipe(pipe_to_child); pipe(pipe_to_parent); int child_pid = fork(); // TODO: Handle case where fork fails. if(child_pid == 0) { printf("C: I'm the child. my pid: %d\n", getpid()); capitalize(pipe_to_child, pipe_to_parent); } else { printf("P: I'm the parent. my pid: %d, child pid: %d\n", getpid(), child_pid); interact(pipe_to_child, pipe_to_parent); // TODO: Wait for child to complete. } } /** * Capitalize the received text and send it back to the parent */ void capitalize() { printf("C: Capitalizing\n"); } /** * Ask the user to enter text and display the capitalized text to the user. */ void interact() { printf("P: Interacting with user\n"); }