What happens internally in Linux Kernel when Process and Thread is created.
In our post , we have came to known that Linux implements threads as standard processes. Let's see in this post, how they are implemented internally. In C, we use fork() to create new process and pthread_create to create a new thread. Both internally uses clone system call provided by Linux Kernel. Process Creation example: #include <stdio.h> int main() { fork(); return 0; } To find the system call :strace ./fork clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fec70651a10) = 4269 Thread Creation Example: #include <stdio.h> #include <pthread.h> void *func(void *arg) { return NULL; } int main(int argc, char *argv[]) { pthread_t thread; pthread_create(&thread,NULL, func, NULL); return 0; } To find the system call: strace ./thread clone(child_stack=0x7f74bf7a2fb0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|C...