fork() system call

Create a new process: use fork() to call system API. This will spawn a child process running from the position, just like forking a GItHub repo.

Child process has its own mem space, regs.

The return value of fork():

Get PID: function getpid()

wait() system call

Wait until child process has exited: function wait() Returns child PID.

When a process calls wait(), it’s immediately blocked until any child process becomes zombie (or simply exits).

When a child process dies, it becomes zombie. If its parent process calls wait(), then it’s cleaned.

If include an integer pointer as parameter, the pointed value will record some information about the exited child process. Normally just use NULL.

exec() system call

This call replaces the context of the process with intended program. Anything else behind this command won’t be run.

exec() can run system commands without shells.

See Tencent Cloud+ article .