#include #include #include #include using namespace std; static int *nptr; int main() { nptr = (int*)mmap(NULL, sizeof *nptr, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); if (nptr != NULL) { int& n = *nptr = 0; for (int i = 1; i < 4; i++) { n++; fork(); cout << "Process pid=" << getpid() << " has n=" << n << endl; } } munmap(nptr, sizeof *nptr); return 0; }