#include #include #include #include void thread_func() { printf( "thread pid=%d, thread tid=%d\n", getpid(), syscall( SYS_gettid ) ); size_t one_hundred_mb = 100 * 1024 * 1024; void * allocatedChunk = malloc ( one_hundred_mb ); memset( allocatedChunk, 0, one_hundred_mb ); if ( allocatedChunk == NULL ) { printf("couldn't allocate\n"); } else { int tid = syscall( SYS_gettid ); printf( "PID: %d, TID: %d - has allocated 100mb\n", getpid(), syscall( SYS_gettid ) ); } sleep(1000); } void main() { printf( "main pid=%d, main tid=%d\n", getpid(), syscall( SYS_gettid ) ); pthread_t thread1; pthread_create( &thread1, NULL, (void *)&thread_func, NULL); /* pid_t childpid; childpid = fork(); if ( childpid >= 0 ) { if ( childpid == 0 ) { thread_func(); // child } else { sleep(1000); // parent } } else { perror("fork"); exit(0); } */ sleep(1000); }