A system call is just what its name implies—a request for the operating system to do something on behalf of the user’s program.



  • open() 
  •  read() 
  •  write() 
  •  close() 
  •  wait() 
  •  fork() 
  •  exec() 
open()  


Next is the open() system call.  open() lets you open a file for reading, writing, or reading and writing.

      int open(file_name, mode) 
      where file_name is a pointer to the character string that names the file and mode defines the file's access permissions if the file is being created.

read() and write()

The read() system call does all input and the write() system call does all output.  When used together, they provide all the tools necessary to  do input and output. 
     Both read() and write() take three arguments.  Their prototypes are:
     int read(file_descriptor, buffer_pointer, transfer_size)
     int file_descriptor;
     char *buffer_pointer;
unsigned transfer_size;
     int write(file_descriptor, buffer_pointer, transfer_size)
     int file_descriptor;
     char *buffer_pointer;
     unsigned transfer_size;
     where file_descriptor identifies the I/O channel, buffer_pointer points  to the area in memory where the data is stored  for a read() or where  the data is taken for a write(), and transfer_size defines the maximum.

close() 

      To close a channel, use the close() system call.  The prototype for the

      close() system call is: 
      int close(file_descriptor)
      int file_descriptor;

wait() 

  • The wait system call suspends the calling process until one of its immediate children terminates. 
  • If the call is successful, the process ID of the terminating child is returned. 
  • Zombie process—a process that has terminated but whose exit status has not yet been received by its parent process or by init.  
  • pid_t wait(int *status); 

where status is an integer value where the UNIX system stores the value returned by the child process.

fork()

When the fork system call is executed, a new process is created which consists of a copy of the address space of the parent.
The return code for the fork is zero for the child process and the process identifier of a child is returned to the parent process. 
On success, both processes continue execution at the instruction after the fork call.  On failure, -1 is returned to the parent process.

exec() 


  • Typically the exec system call is used after a fork system call by one of the two processes to replace the process’ memory space with a new executable program.  
  • The new process image is constructed from an ordinary, executable file. 
  • There can be no return from a successful exec because the calling process image is overlaid by the new process image.