Process Types

A classical Unix process is an application that consists of binary code, a chronological thread (the computer follows a single path through the code, no other paths run at the same time), and a set of resources allocated to the application — for example, memory, files, and so on. New processes are generated using the fork and exec system calls:

□ fork generates an identical copy of the current process; this copy is known as a child process. All resources of the original process are copied in a suitable way so that after the system call there are two independent instances of the original process. These instances are not linked in any way but have, for example, the same set of open files, the same working directory, the same data in memory (each with its own copy of the data), and so on.3

□ exec replaces a running process with another application loaded from an executable binary file. In other words, a new program is loaded. Because exec does not create a new process, an old program must first be duplicated using fork, and then exec must be called to generate an additional application on the system.

Linux also provides the clone system call in addition to the two calls above that are available in all Unix flavors and date back to very early days. In principle, clone works in the same way as fork, but the new process is not independent of its parent process and can share some resources with it. It is possible to specify which resources are to be shared and which are to be copied — for example, data in memory, open files, or the installed signal handlers of the parent process.

clone is used to implement threads. However, the system call alone is not enough to do this. Libraries are also needed in userspace to complete implementation. Examples of such libraries are Linuxthreads and Next Generation Posix Threads.

Continue reading here: Concept

Was this article helpful?

0 0