Learning more about process creation
A common practice in system programming is to follow a strict timeline for process creation and execution. Programmers use either daemons, such as systemd
and other in-house developed solutions, or startup scripts. We can use the Terminal as well but this is mostly for when we repair the system’s state and restore it, or test a given functionality. Another way to initiate processes from our code is through system calls. You probably know some of them, such as fork()
and vfork()
.
Introducing fork()
Let’s look at an example; we’ll discuss it afterward:
#include <iostream> #include <unistd.h> using namespace std; void process_creator() {     if (fork() == 0) // {1}         cout << "Child with pid: " << getpid() << endl;     else         cout << "Parent...