Every process has a unique _?_.
process ID or PID.
Special Processes: 0:
the swapper (long-term scheduler process - kernel)
init process (runs as superuser)
unique process IDs are non-_?_ integers
UNIX/LINUX: These system calls return the various identifiers associated with the process(?)
Unix C libraries to #include for gitpid() sys-calls
- #include <sys/types.h>
- #include <unistd.h>
pid_t getpid(void) = ?
returns PID of the caller
pid_t getppid(void); =?
returns the PID of parent.
returns the real user-ID of process.
returns effective user-ID of process
returns the real group-ID of process
returns effective group-ID of process
Process Creation: All processes (except the first process created when the system is booted) are created by another process (parent process)They are said to be _?_ of the process that created them.
children of the process that created them.
A process created by another process is referred to as the _?_ of that process.
A process created by another process is referred to as the child of the creator process.
UNIX creates processes through the _?_ system call.
fork() system call..called forking a process.
When a process forks the OS does WHAT?
an identical copy
of the forking process
- new address space
- and a new PCB.
When a process forks the only resource shared by the parent and the child are _?_
the opened files.
pid_t fork(void) creates new __?__
fork() is called _?_ but returns _?_.
is called once, but returns twice.
fork() returns a PID as follows:
- Parent process gets the pid of the child process.
- Child process gets 0.
Both child and parent continue _?_ at the statement following the call to fork()
int pid; // to store _?_ pid...
pid = fork();if (pid == 0)
// code executed by __?__
_exit(1); //terminates _?_}
// code executed by the _?_
- int pid; // to store child pid.
- //code executed by the child.
- _exit(1) //terminates the child.} // code executed by the parent.
File Sharing: All file descriptors to open files in the parent are _?_ in the child process
Both the parent and the child share all _?_ open at time of the fork()
At the time of the fork() call... if both parent and child write to same descriptor without synchronization, the outputs will be _?__
- Too many processes in the system
- Total number of processes for the real user-ID exceeds system’s limit
pid_t vfork(void): works like fork except for _?_
- Both parent and child share the same address space
- Both run in the address space of the parent
exec() in the case of vfork(): what happens when an exec() sys call happens after a vfork() is called.
New address space created when the exec() system call is made.
A race condition occurs when...
two or more processes are trying to do something with shared data, and the final outcome depends on the order in which the processes run.
A parent process can wait for the termination of one of its children by doing:
which returns the process ID of the child whose termination was caught.
To wait for the completion of a specific child, say the one with process ID equal to this_child, use:
while (wait(0) != this_child) /* empty */
pid_t wait(int *statloc);pid_t
waitpid(pid_t pid, int *statloc, int options);
*statloc is ?
a pointer to an integer used to store the termination status of the process handled by the wait.
To load a different program in the child's address space:
execve(full_pathname, arg_vector, envp)
execve(full_pathname, arg_vector, envp);
the pathname of the executable to be fetched
execve(full_pathname, arg_vector, envp); arg_vector is...
is an array of pointers to the individual argument strings
execve(full_pathname, arg_vector, envp); envp is...
an array of pointers pointing to the environment strings: it is also terminated by a NULL.
execve(full_pathname, arg_vector, envp); arg_vector contains...
the name of the program as it appears in the command line
execve(full_pathname, arg_vector, envp); envp consists of....
a list of the environment variables of your shell.
The process receiving a signal can catch it by.....
- using the signal() system call;
- the process catching the signal will not terminate.
Two signals cannot be caught
- the 9th signal, SIGKILL
- the 23rd signal, SIGTSTOP
WAIT: pid_t waitpid(pid_t pid, int *statloc, int options); define pid, statloc, options
- pid - process id of process to wait for.
- statloc -pointer to an integer used to store the termination status of the process handled by the wait.
- options - allows the caller to have further control over how the wait occurs
- WNOHANG -waitpid() will not block if the child specified by pidis not immediately available (i.e., already terminated)
- WUNTRACED - Causes waitpid() to return the status for any stoppedchild specified by pidwhich has not had its status reported since it was stopped
A process executing wait() or waitpid() can...
- Block - If all of its children are still running
- Return immediately with the termination status of a child... if a child has terminated and is waiting for its termination status to be fetched
- Return immediately with an error -- If it does not have any child processes
Waitpid MACRO: True if status was returned for a child that terminated normally.
Waitpid MACRO: Fetches the low order 8 bits of the argument to exit() or _exit().
Waitpid MACRO: -True if status was returned for a child that terminated abnormally (by an uncaught signal)
Waitpid MACRO: Fetches the signal number which caused termination
Wait MACROS:-True if a core file was generated for the terminated process.
Waitpid MACRO:True if status was returned for a child that is currently stopped
Waitpid MACRO: Fetches the signal number that caused the child to stop
Waitpid Return values: -1:
waitpid() waits for any process [same as wait()]
Waitpid Return values: >0:
waits for child with specified pid #
Waitpid Return values: 0:
waits for any child whose process group ID number equals that of the calling process
Waitpid Return values:<-1:
waits for any child whose process group ID number equals the absolute value of the specified pid #