System Calls
System Calls
System Calls
System Calls
By
Neha Hulkoti & Kavya Bhat
System calls
The UNIX system provides several system calls
to create and end program, to send and receive
software interrupts, to allocate memory, and to do
other useful jobs for a process.
Four system calls are provided for creating a
process, ending a process, and waiting for a
process to complete. These system calls are
fork(), the "exec" family, wait(), and exit().
Fork( )
The exec family of system calls transforms an
executable binary file into a process that overlays the
process that made the exec system call.
The UNIX system does not create a new process
in response to an exec system call.
To create a new process, you must use the fork()
system call. The prototype for the fork() system call
is:
int fork()
fork() causes the UNIX system to create a new
process, called the "child process", with a new
process ID.
The contents of the child process are identical to
the contents of the parent process.
The new process inherits several
characteristics of the old process.
Among the characteristics inherited are:
The environment.
All signal settings.
The set user ID and set group ID status.
The time left until an alarm clock signal.
The current working directory and the root
directory.
The file creation mask as established with
umask().
The child process begins executing and the parent
process continues executing at the return from the
fork() system call.
This is difficult to understand at first because you
only call fork() once, yet it returns twice -- once per
process.
To differentiate which process is which, fork()
returns zero in the child process and non-zero (the
child's process ID) in the parent process.
exec routines are usually called after a call to
fork(). This combination, known as a fork/exec,
allows a process to create a child to execute a
command, so that the parent doesn't destroy itself
through an exec.
Most command interpreters (e.g. the shell) on
UNIX use fork and exec.
exec()