Fork:
Fork is nothing more than a new process that looks exactly like the old or parent process, but still it is a different process with a different process identifier and having its own memory. The parent process creates a separate address space for the child. Both the parent and the child processes have the same code segment, but are executed independently of each other.
The simplest example of forcing is when you run a command on a shell in unix / linux. Each time the user issues a command, the shell wags the child process and the task is completed.
When the fork system call is issued, a copy of all pages corresponding to the parent process is created, loaded into a separate OS memory location for the child process, but in some cases this is not required. As with the 'exec system calls, there is no need to copy the parent pages of the process, because execv replaces the address space of the parent process itself.
A few things that you should pay attention to forking are:
- The child process will have its own unique process identifier.
- The child process must have its own copy of the parent file descriptor.
- File locks set by the parent process must not be inherited by the child process.
- Any semaphores open in the parent process must also be open in the child process.
- The child process must have its own copy of the parent's message queue descriptors.
- The child will have its own address space and memory.
Topics:
Threads are light weight processes (LWP). Traditionally, a thread is simply a state of the CPU (and some other minimal state) with a process containing remains (data, stack, I / O, signals). Threads require less overhead than forking or spawn a new process because the system does not initialize the new system virtual memory space and process environment. Although most effective in a multiprocessor system where a process flow can be scheduled to run on another processor, thereby gaining speed through parallel or distributed processing, gains are also found in single-processor systems that use latency in I / O and other system functions that can stop process execution.
Threads of the same process resource:
- Process instructions
- Most data
- open files (descriptors)
- signals and signal handlers
- current working directory
- User id and group
More information can be found here .
GeekRide Jan 13 '13 at 15:23 2013-01-13 15:23
source share