What are the properties inherited by a child process during fork()?
Answer:
Properties inherited:
* open file descriptors
* real uid, real gid, effective uid, effective group id
* process gid
* controlling terminal
* set-user-ID flag and set-group-ID flag
* current working directory
* root dir
* file mode creation mask
* signal mask
* Environment
Differences:
* alarms.
* pending signals.
( selected from Steven Richards, p.192 )
Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts
Memory Layout of a Program in UNIX
Memory layout of a Program in a UNIX-environment:
Reference : "The Environment of a Unix Process" in Advanced Programming in the UNIX Environment Richard Stevens, p.168
Reference : "The Environment of a Unix Process" in Advanced Programming in the UNIX Environment Richard Stevens, p.168
(High address)
+-------------------+
| | cmd line args and env vars
| |
+-------------------+
| stack |
+-------------------+
| ↓ |
| |
| ↑ |
+-------------------+
| heap |
+-------------------+
|Uninitialized data | init to zero by exec
| (bss) |
+-------------------+ _
| initialized data | |
+-------------------+ |--read from program file by exec
| text | |
+-------------------+ _|
(Low address)
Difference between fork(), clone().
What is the difference between fork(), clone(), and pthread_create() system calls.?
Answer:
Excepts from the manpage:++
clone() creates a new process, in a manner similar to fork(). It is actually a library function layered on top of the underlying clone() system call, hereinafter referred to as sys_clone.
Unlike fork(), these calls allow the child process to share parts of its execution context with the calling process, such as the memory space, the table of file descriptors, and the table of signal handlers.
The main use of clone() is to implement threads: multiple threads of control in a program that run concurrently in a shared memory space.
When the child process is created with clone(), it executes the function application fn(arg). (This differs from fork(), where execution continues in the child from the point of the fork() call.) The fn argument is a pointer to a function that is called by the child process at the beginning of its execution. The arg argument is passed to the fn function.
See also:[2]
Answer:
Excepts from the manpage:++
clone() creates a new process, in a manner similar to fork(). It is actually a library function layered on top of the underlying clone() system call, hereinafter referred to as sys_clone.
Unlike fork(), these calls allow the child process to share parts of its execution context with the calling process, such as the memory space, the table of file descriptors, and the table of signal handlers.
The main use of clone() is to implement threads: multiple threads of control in a program that run concurrently in a shared memory space.
When the child process is created with clone(), it executes the function application fn(arg). (This differs from fork(), where execution continues in the child from the point of the fork() call.) The fn argument is a pointer to a function that is called by the child process at the beginning of its execution. The arg argument is passed to the fn function.
See also:[2]
Subscribe to:
Posts (Atom)