Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How systemd tracks fork process with Type=fork

Tags:

fork

systemd

I am interested how systemd tracks child of main process that remains after main process exists?

like image 394
crashtua Avatar asked Jul 05 '26 02:07

crashtua


1 Answers

Systemd is using cgroups for this. Before starting any executable that is defined with a service file, systemd creates a cgroup and puts the executable in it[*]. After that, it doesn't matter how many child processes or how many times the processes in the cgroup have forked. For systemd, they all belong to the same cgroup.

Another good thing to know is that when the parent process dies, child processes of that parent process inherits PID 1 (systemd) as their parent process. This is a unix rule.

[] System first creates a cgroup. Then forks it self and puts the new process in this cgroup. Then calls exec() family calls for your service's ExecStart= binary.

like image 146
Umut Avatar answered Jul 11 '26 22:07

Umut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!