/* unsharedmem.c Started by Jeff Ondich on 4/11/96 Last modified on 9/16/05 This program does not demonstrate how to use shared memory in Linux. */ #include #include #include #include #include char gSharedBuffer[100]; int main( void ) { pid_t pid; int status; /* Initialize the (un)shared memory. */ strcpy( gSharedBuffer, "Mom, there's a singing moose outside!" ); fprintf( stderr, "%s\n", gSharedBuffer ); /* Fork a child process */ pid = fork(); if( pid == -1 ) { perror( "fork() failure" ); } else if( pid != 0 ) { fprintf( stderr, "The parent %d is waiting.\n", getpid() ); wait( &status ); fprintf( stderr, "The state of affairs is: %s\n", gSharedBuffer ); } else { fprintf( stderr, "The child %d will try to scare the moose.\n", getpid() ); strcpy( gSharedBuffer, "The moose is gone now." ); } fprintf( stderr, "%d is quitting\n", getpid() ); return 0; }