-
Process Identifiers
Every process has unique process ID, a non-negative integer. Process ID 0 is swapper. Process ID 1 is usually the init process and is invoked by the kernel at the end of the bootstrap procedure. The init process never dies. It is a normal user process, not a system process within the kernel, like the swapper, although it does run with super user privileges.
-
Fork Function
pid_t fork(void)
A technique called copy-on-write (COW) is used. These regions are shared by the parent and child and have their protection changed by the kernel to read-only. If either process tries to modify these regions, the kernel then makes a copy of that piece of memory only, typically a “page” in a virtual memory system.
The parent and child share a file table entry for every open descriptor. It is import that the parent and child share the same of file offset.
-
Child process inherited from parent process:
-
Real user ID, real group ID, effective user ID, effective group ID
-
Supplementary group ID
-
Process group ID
-
Session ID
-
Controlling terminal
-
The set-user-ID and set-group-ID flags
-
Current working directory
-
Root directory
-
File mode creation mask
-
Signal mask and dispositions
-
The close-on exec flag from any open file descriptors
-
Environment
-
Attached shared memory segments
-
Memory mappings
-
Resource limits
-
The differences between child and parent are:
-
The return value from fork
-
The process IDs are different
-
The two processes have different parent process IDs
-
The child’s tms values are set to 0
-
File lock set by the parent are not inherited by the child
-
Pending alarms are cleared for the child
-
The set of pending signals for the child is set to the empty set
-
vfork Function
The vfork function is intended to create a new process when the purpose of the new process is to exec a new program. The vfork function creates the new process, just like fork, without copying the address space of the parent into the child, as the child will reference that address space; the child simply call exec(or exit) right after the vfork. Instead, while the child is running and until it calls either exec or exit, the child runs in the address space of the parent.
Another difference between the two functions is that vfork guarantees that the child runs first, until the child calls exec or exit.
What happens if the parent terminates before the child? The answer is that the init process becomes the parent process of any process whose parent terminates. We say that the process has been inherited by init.
-
Change User IDs and Group IDs
int setuid(uid_t uid);
int setgid(gid_t gid);
Below table show ways to change the three user IDs:
ID |
exec |
setuid(uid) | ||
set-user-ID bit off |
set-user-ID bit on |
super user |
unprivileged user | |
real user ID effective user ID
saved set-user-ID |
unchanged unchanged
copied form effective user ID |
unchanged set from user ID of grogram file copied from effective user ID |
set to uid set to uid
set to uid |
unchaged set to uid
unchaged |
-
User Identification
char * getlogin(void)
The getlogin function provides a way to fetch that login name. This function cal fail if the process is not attached to a terminal that a user longed in to. We normally call these processes daemons.