Distinction Between Program Vs Process: Taken from here
- Program is on disk (persistent mem) and contains only set of instructions to accomplish something
- Process is an executing instance of a program
- Therefore it is fair to say a program is static and a process is a dynamic program
exec() vs fork()
- exec() is used to load a program into a previously terminated process’s address space and inherits the previous process’s resources
- fork() is used to create a child process based upon its parent. It is an exact duplicate of the parent process
- Any process needs to point to both its parent and all child preocesses
- _exit() terminates a process. Done by releasing all used resources and sending the parent a SIGCHILD signal.
Zombie Processes: A terminated process which remains in the process table
- Zombie processes remain in the process table until they recieve a wait4() system call from its parent then the parent deletes the process descriptor.
- wait4() returns the resource usage information about the child in the structure pointed to (PID and such)
- waitpid()
- It is possible that a parent can terminate by accident which will leave child processes running and thus taking up precious resources
- This is solved by system process init run at system initialization. init will make all children point to it and then periodic run wait4() to clear useless children
Process Groups and Login Sessions
- Process Groups are groups of processes required to complete a single task/job
- Eg. ls | sort: list all directory and sort the shell acts on two processes which now are identified by a group ID (usually the first PID)
- Login Session: Contains all descendant processes from the initial process from start.
- All processes in a gropu must come from the same login session
Background VS Foreground Processes
- Background processes do not need access to terminal and can run in the “background” without taking over the shell.
- Shells can continue to receive more commands while having processes running in the background
$ command &
- Shells can continue to receive more commands while having processes running in the background
- Foreground processes need direct access to terminal and must be terminated before other commands may be input.
- These types of processes might be a GUI based process
$ command
- These types of processes might be a GUI based process