0% found this document useful (0 votes)
20 views

Sys/types H

The document summarizes key system calls related to process management in Linux: 1. The fork() system call is used to create processes and returns different process IDs to the parent and child processes. The child process is an exact copy of the parent process except for its unique process ID. 2. The wait() system call blocks the calling process until one of its child processes exits, returning the process ID of the completed child process. 3. The exec() family of functions replaces the current process image with a new image from an executable file, without changing the process ID. Open files remain open after exec.

Uploaded by

Mayur Dutta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Sys/types H

The document summarizes key system calls related to process management in Linux: 1. The fork() system call is used to create processes and returns different process IDs to the parent and child processes. The child process is an exact copy of the parent process except for its unique process ID. 2. The wait() system call blocks the calling process until one of its child processes exits, returning the process ID of the completed child process. 3. The exec() family of functions replaces the current process image with a new image from an executable file, without changing the process ID. Open files remain open after exec.

Uploaded by

Mayur Dutta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Non-preemptive scheduling Pre-emptive scheduling

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:

• The child process shall have a unique process ID.


• The child process ID also shall not match any active process group ID.
• The child process shall have a different parent process ID, which shall be the process ID of the
calling process.
• The child process shall have its own copy of the parent's file descriptors. Each of the child's file
descriptors shall refer to the same open file description with the corresponding file descriptor of
the parent.
• The child process shall have its own copy of the parent's open directory streams. Each open
directory stream in the child process may share directory stream positioning with the
corresponding directory stream of the parent.

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.

You might also like