System calls
Bellow are listed the system calls that give NuShell its functionality along with a small explanation of their use.
- fork: Used to create a new process by duplicating the calling process. It is the basic process creation primitive.
- exec: Used to transform a process by overlaying its memory space with a new program.
- wait: Used to allow one process to wait until another related process finishes (i.e., this system call allows a parent to wait for any child). Thus, this system call provides a simple process synchronization mechanism.
- exit: Used to terminate a process.
- execvp: This is system call that belongs to the exec family. The main difference is that both the shell and execvp basically searches everywhere for commands (e.g., first in /bin, then /usr/bin and finally /usr/username/mybin).
- waitpid: Used instead of the system call wait() when the parent wants to wait for a specific child process.
- dup2: This system call makes newfd be the copy of oldfd, closing newfd first if necessary.
- pipe: This system call is typically used to establish a unidirectional indirect communication channel between processes. A process uses the pipe by writing data to it using the write system call. Data written to a pipe is stored in a buffer where it waits to be read by another process at the other end of the pipe using a read class="italic"> system call. Data is handled on a first come first serve basis (FIFO). If successful, a call to pipe() returns a pointer to an array of two file descriptors, read (index 0) and write (index 1). The pipe system call is used in conjunction with the fork system call. The size of the pipe is finite. Only a certain number of bytes can be in the pipe before a write will block. The minimum is 512 bytes.
- sigaction: Signals are a simple form of inter-process communication. Its function is to communicate events between processes. This system function allows a process to setup a response when a signal is sent to it. For this assignment, the requirement was to trap just SIGINT but I chose to trap SIGKILL in addition to SIGINT.