When you start a system, the first process started is INIT, which gets the PID of 1. Afterwards, all other processes are child of INIT (PID: 1) and each of them can have child processes and so on.
My question is, how are processes related when it comes to memory and cpu ? I am aware that each process can have multiple threads and that it each process has its own heap. In that case, how are parent and child processes related when it comes to resources ?
If, for example a process has a limit on the CPU amount it can use and that limit is set by the cgroup the process it's in, how would that affect child processes ? Does the CPU-amount of the parent process increase as the CPU-amount of its child processes increase ?
CodePudding user response:
In general, processes and their child processes are related in terms of resource usage in the following ways:
Memory: Each process has its own private memory space, which includes its own heap and stack. This means that a process cannot directly access the memory of its child processes or any other processes. However, the total amount of memory used by a process and its child processes is accounted for in the process's resource usage. For example, if a process has a certain limit on the amount of memory it can use and it creates a child process that uses a large amount of memory, the parent process's memory usage will increase by the amount of memory used by the child process.
CPU: The CPU usage of a process and its child processes is also accounted for in the process's resource usage. If a process has a limit on the amount of CPU it can use, this limit will also apply to its child processes. However, the child processes may also have their own CPU limits set by their respective cgroups. In this case, the CPU usage of the parent process may not necessarily increase as the CPU usage of its child processes increases, as the child processes may be limited by their own CPU limits.
It's also worth noting that the relationship between processes and their child processes can be more complex in certain situations. For example, a process may create multiple child processes, and these child processes may create their own child processes, forming a tree-like structure. In this case, the resource usage of each process in the tree would be accounted for in the resource usage of its parent process.