Terminal Processes Flashcards
Foreground
Processes executed on terminal run in foreground by default (recieve input from keyboard, send output to screen)
Background
For processes that don’t require keyboard input, can send to background to run in parallel with & (or ^Z, then bg)
&
symbol/character represents “execution in the background”
./program &
nohup
(no hang up): used as a prefix when starting a background process so you can log off and the process keeps executing
nice
used as a prefix for command to modify niceness(scheduling priority) , -20 (most favorable) and +19 (least favorable)
Gary’s Analogy: you don’t expect nice to be something to be a command, if you’re nice you’ll let other people go ahead of you.
SIGCHILD
death of a child signal
Parent reaps
What is a PPID?
Parent Process ID: Every process has a parent that started it, tracked using PPID
init or launchd
Processes are heirarchial. init or launchd can be thought of as the root of the process tree
pstree
pstree: this command shows the relationship of all processes in a tree-like structure
UID (Process ID)
UID: user ID that this process belongs to (the person running it)
C (Process ID)
CPU utilization of processor
TTY
Terminal type associated with the process
TIME
CPU time taken by the process
CMD
The command that started this process
Child Process: fork( )
In unix a child process is created when the parent process invoke the fork ( )
Piping v. Redirecting
Piping is redirecting ouput from one command to another command
Extracting and analyzing data from large files
Redirecting
Redirecting output of one command to a file
> redirects standard output overwriting over a file.
2> for just stderrr
» appends from stdout
< redirects stand input
ex. : $ who | wc -l -> lists users and pipes the word count
echo cat v. cat echo
echo cat : will print cat on the screen
cat echo : will look for file named echo, and if it doesn’t find it , it throw error
What happens when a file exists/doesn’t exists?
Processes : ready, blocked, running
ready :
blocked :
running : running in the background and running in foreground
What is a process? A program in execution
How to start a process? execute a utility, program or script
Child Process: fork()
fork() in a unix child process created with the parent process invoke the fork() system call.
Child process are initially identical copies of their parent until they execute their command!
child process : fork returns 0
parent process : fork returns PID of child
Daemon Process: a program run it he background process without being controlled by an active user.
Sometimes daemon processes are adopted by init
Zombie processes: process that has completed execution, memory and resources are deallocated, but still has an entry in the process table (z)
A zombie is not an orphan!
Resource leak: PID is unusable until parent process reads child’s exit status (wait() system call)
Foreground: processes executed on terminal run in the foreground by default (recieve input from keyboard, send output to screen )
Cannot run another command until previous command finishes