GNULinux Processes


GNU/Linux Processes

GNU/Linux presents two fundamental types of processes. These are kernel threads and user processes . We ll focus our attention here to user processes (those created by fork and clone ). Kernel threads are created within the kernel context via the kernel__thread() function.

When a subprocess is created (via fork ), a new child task is created with a copy of the memory used by the original parent task. This memory is separate between the two processes. Any variables present when the fork takes place are available to the child. But after the fork completes, any changes that the parent makes to a variable are not seen by the child. This is important to consider when using the fork API function.

Note  

When a new task is created, the memory space used by the parent isn t actually copied to the child. Instead, both the parent and child reference the same memory space, with the memory pages marked as copy-on-write . When any of the processes attempt to write to the memory, a new set of memory pages is created for the process that is private to it alone. In this way, creating a new process is an efficient mechanism, with copying of the memory space deferred until writes take place. In the default case, the child process inherits open file descriptors, the memory image, and CPU state (such as the PC and assorted registers).

Certain elements are not copied from the parent and instead are created specifically for the child. We ll look at examples of these in the following sections. What s relevant to understand at this stage is that a process can create subprocesses (known as children ) and generally control them.




GNU/Linux Application Programming
GNU/Linux Application Programming (Programming Series)
ISBN: 1584505680
EAN: 2147483647
Year: 2006
Pages: 203
Authors: M. Tim Jones

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net