Processes API

OSTEP - Virtualization - Processes API

Unix creates a process with a pair of system calls: fork() exec() A third system call can be used by a process to wait until a process it has created to complete. wait() fork() It is used to create a new process In the following example: #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char* argv[]) { printf("Hello world (pid:%d)\n", (int) getpid()); // rc = return code int rc = fork(); if (rc < 0) { // Fork failed fprintf(stderr, "Fork failed\n"); exit(1); } else if (rc == 0) { // Child (new process) printf("Hello, I'm a child (pid:%d)\n", (int) getpid()); } else { // Parent goes down this path printf("Hello, I am a parent of %d (pid:%d)\n", rc, (int) getpid()); } return 0; } A new child process is created when fork() is called.
Read more