function for creating new processes | fork()
child is almost the same as parent
returns child ID in parent
returns 0 in child
returns -1 on error |
formula for number of processes created | 2^n
n-number of times we call fork() |
function replaces the current process with a new program | exec();
program changes while process remains |
How the root process is called? | init is the first process initialized
if a parent dies ten children are adopted by init
ID=1
in linux:
init=systemd |
returns the process ID of the parent of the calling process | getppid() |
returns the process ID of the calling process | getpid(); |
what is zombie prcoess | A zombie process is a process whose execution is completed but it still has an entry in the process table.
Zombie processes don't use any system resources but they do retain their process ID.
init adopts all the zombies |
What are process groups | Processes started by a single command are organized into groups
Processes are free to migrate to ther groups or start new ones
setpgid()
setpgrp() |
What are sessions | One or more process groups can form a session
Unix shells create one session per login
Processes cannot migrate to other sessions, yet they can start new sessions setsid() |
What is job control | Gratning controlling terminal access to process groups in a session |
command that shows running processes as a tree | pstree
pstree -p -includes PIDs after each process name |
command for printing statistics of running processes | ps
ps -ef -full listing on every process |
command that prints PID od a process | pgrep process_name |
command that displays dynamic, real time information on running proceesses | top
htop -improved version of top |
In which file system can we access information on given process? | /proc/<PID>/ directory |
What are signals? | Signals are the simples communication method. No data except signal type is deliver to a process
They notify about system events |
Who can root send signals to?
Who can non-root process send signal to? | root can send signal to every process
non-root can send only signals to processes running on behalf of the same user |
How many signals are defined? | 28 |
Do we have user defined signals on unix? | Yes 2
SIGUSR1
SIGUSR2 |
Can signals be blocked, ignored or intercepted? | Yes, expcept for two:
SIGKILL
SIGSTOP
they can not be |
What happens with blocked signalas? | They are postponed, not deliver until unblocked |
What happens with ignored signals? | They wont be delivered to process |
What happens with signals that are not blocked nor ignored? | They interrupt current proces or function execution |
What is a signal handler? | It is a short function invoked when receiving a signal |
What happens if no signal handler is defined? | default action in most cases process termination |
Signal clasification by origin | natural-genrated by some event
synthetic-by calling a system call
every natural signal can be generated synthetically
SIGUSR1 SIGUSR2 can be generated synthetically only |
How to terminate a process using signal?
Which command is used? | Kill command sends a signal to a process which terminates the process. If the user doesn’t specify any signal which is to be sent along with kill command then default SIGTERM signal is sent that terminates the process.
kill [signal type] <PID>
where PID stands for process ID |
What is the difference between
terminating
stopping
pocess? | terminating results in calling exit() and changing process to dead
stopping means freezing, the execution is suspended it still occupies resources |
displays status of all jobs in current session | jobs |
How to start process in the background? | process_name & |
command used to place foreground job in the background | bg |
command used to place a job in foreground | fg |
What is process tracing | Tool for tracing and displaying all system calls made by a process |
How to trace a process> | strace |