Sys/types H
Sys/types H
1.If once a process has been allocated CPU 1.the CPU can be taken away before the
then the CPU cannot be taken away from completion of the process
that process.
2.no preference is given when a higher 2. it is useful when a higher priority job
priority job cames arrives as the CPU can be allocated to it
Deallocating from the lower priority
process
3.example:-- FCFS CPU algorithm 3. Round –Robin CPU algorithm
SYSTEM CALL
FORK(): System call fork() is used to create processes. It takes no arguments and returns a process ID. The
purpose of fork() is to create a new process, which becomes the child process of the caller. After a new child
process is created, both processes will execute the next instruction following the fork() system call. Therefore,
we have to distinguish the parent from the child. This can be done by testing the returned value of fork():
• If fork() returns a negative value, the creation of a child process was unsuccessful.
• fork() returns a zero to the newly created child process.
• fork() returns a positive value, the process ID of the child process, to the parent. The returned
process ID is of type pid_t defined in sys/types.h. Normally, the process ID is an integer.
Moreover, a process can use function getpid() to retrieve the process ID assigned to this process.
The new process (child process) shall be an exact copy of the calling process (parent process) except as
detailed below:
WAIT():--
This function blocks the calling process until one of its child processes exits or a signal is received.
wait() takes the address of an integer variable and returns the process ID of the completed process.
Some flags that indicate the completion status of the child process are passed back with the integer
pointer. One of the main purposes of wait() is to wait for completion of child processes. The execution
of wait() could have two possible situations.
1. If there are at least one child processes running when the call to wait() is made, the caller will be
blocked until one of its child processes exits. At that moment, the caller resumes its execution.
2. If there is no child process running when the call to wait() is made, then this wait() has no effect
at all. That is, it is as if no wait() is there.
Exec:
The exec family of functions shall replace the current process image with a new process image. The new
image shall be constructed from a regular, executable file called the new process image file. There shall
be no return from a successful exec, because the calling process image is overlaid by the new process
image.
Any process mayexec (cause execution of) a file.
Doing an exec does not change the process ID; the process that did the exec persists, but after the
exec it is executing a different program.
Files that were open before the exec remain open afterwards.