#include #include #include #include #define DEFAULT_ALLOC_SIZE (1024*1024) int main(int argc, char *argv[]) { pid_t pid; char *p; int len; int num; if(argc != 2) { len = DEFAULT_ALLOC_SIZE; } else { len = strtol(argv[1], NULL, 10); if(len <= 0) { len = DEFAULT_ALLOC_SIZE; } } for(num=0; ; num++) { printf("\n*** Press return key to fork.(childlen=%d,len=%d)\n", num, len); getchar(); pid = fork(); if(pid == -1) { perror("fork"); return 1; } else if(pid) { /* child process */ int i; p = malloc(len); printf("*** pid=%d allocate=%p len=%d\n", pid, p, len); while(1) { for(i=0; i