#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
        int pid;

        int id = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0666);
        int *x = (int*)shmat(id, NULL, 0);
        *x = 0;
        switch(pid=fork()) {
        case -1: perror("fork"); exit(1);
        case 0: while(1) {
                        ++*x;
                        sleep(1);
                }
                break;
        default: while(1) {
                        printf("x = %d\n", *x);
                        sleep(1);
                }
                break;
        }
}
