Topic 6 - Process & Job Control 1 Flashcards
All processes are handled and managed by:
the kernel through a scheduling services called the scheduler
In a single-processor computer, how many processes can be running at a time?
Only one process
What are the statuses a process can have at a time?
Either one of three:
1) Running
2) Ready to run
3) Blocked or sleeping
What does a Running Process mean?
Is executing for a short slice of time only
What does a Ready Process mean?
It could use the CPU immediately if it is allowed to do so.
The scheduler decides which of the ready processes to run next
What does a Blocked or Sleeping process mean?
Waiting for an event to occur, e.g., I/O or signal
Can you go from:
1) Running to Ready to Run?
2) Running to Blocked / Sleeping?
3) Ready to Run to Running?
4) Ready to Run to Blocked / Sleeping?
5) Blocked / Sleeping to Running?
6) Blocked / Sleeping to Ready to Run?
1) Yes
2) Yes
3) Yes
4) No
5) No
6) Yes
How does the system keep track of all the processes?
A process table
What is the first thing that happens when a process is created?
A process ID is created, or simply, PID.
Within Unix, every object is represented by?
Either a file or a process.
A process is a program that is started by:
Either a user or the system
What maintains the process table?
Maintained by the kernel
What are the characteristics of a process table?
1) Indexed by the PID
2) Contains one entry for each process to store its attributes
List the 3 things a scheduler does:
1) Maintains a list of all the processes waiting to execute
2) Chooses one process at a time, and gives it change to run for short time called time slices (typically 10 milliseconds).
3) Saves data related to the interrupted processes so that they can be resumed later
What happens when a process needs the kernel to perform a service?
It sends a request (a system call) which will create new a process.
System calls provides an __________ between________ and _______.
an essential interface between a process and the operating system
What is the rule of process creation?
Every created process is a child process where it was generated from another parent process. (Except the first process during boot up)
There are 4 types of System Calls:
1) File-related calls
2) Information-related calls
3) Communication-related calls
4) Process-related calls
Define:
1) File-related calls
2) Information-related calls
3) Communication-related calls
4) Process-related calls
1) Opening- closing reading from or writing file
2) Information related calls - getting date / time
3) interprocess communication
4) Creating, executing, stopping a process
Some of the system calls that co-ordinate processes include the following. Describe them. Fork: Exec: Wait: Exit: Kill:
Fork - creates a copy (child) of current process (parent)
Exec - changes the program that a process is running
Wait - forces a process to pause
Exit - terminate a process
Kill - send a signal to another process
What are the two types of commands?
1) Internal Commands
2) External Commands
Define Internal Commands
Intercepted directly by the shell (no need to create a new process)
Define External commands
Required the shell to run a separate program (need to create a new process)
How do you run an external command?
Use the fork system call to create a duplicate of the currently running program. Key point here is currently running program is duplicated.
The fork() command returns what?
- Returns the child PID (a positive number) to the parent process
- 0 to the child process
- A negative value, the creation of a child process was unsuccessful
How do you identify a child process?
Fork() returns 0
The child process uses an exec system call to:
to change itself from a process running the shell into a process running the external command
At the same time a child process is made & running, what is the parent process doing?
- identifies itself by a positive value from the return value of the fork
- Uses the Wait system call to pause itself until the child is finished the execution
Go through the steps when a child process finishes execution.
1) Uses Exit system call
a) send a signal to the parent process indicating the it is done
b) go to a zombie state waiting for the terminating status to be accepted
2) Parent process receives a wake up signal from child
a) Informs kernel to do 2 things;
1) De-allocate the child’s used resources
2) Removes the child PID from the process table, killing the child
What does Process#0 do?
- Initializes many data structures needed by the kernel.
- At the end of the boot procedure, process#0 forks process#1 and then disappears by terminating itself
How is Process#0 created?
kernel creates it by hand without forking
What is another name for Process#1?
the init process
What does Process#1 / the init process do?
Carries out the rest of the steps that are necessary to set up the kernel and finishes the boot process (in doing so, many processes are created by init).
What is the only living ancestor of all other processes in the system?
The init process (process#1)
Describe process#1 besides what it does.
- Is the first process in the process table
- stays there until the system is shut down
- Is the only living ancestor of all other processes in the system
What happens when a parent process unexpectedly dies? Does the child die prematurely? Do we have a rogue child process that lives on forever without a parent to kill it and keeps resources hostage?
- Called an orphan
- The child will keep executing until its done.
- Process#1 automatically adopts all orphan process and receives the control from the child process when its finished executing it
- Informs the kernel to de=allocate the child used resources and kill it
Define: job
A job refers to all the processes that are necessary to execute an entire command line.
How do you run a command in the background?
Use the “&” symbol at the end of the command line.
How do you send a signal to a process?
Using the Kill command
What is displayed / seen by the user when a background command is given to the shell?
1) The shell will display the job number (job ID) that identifies the command
2) display the Process ID (PID) number for each running process in the background
3) Give you another prompt
Describe the Kill command:
A command used to send a signal to a process.
It is a wrapper around the kill() system call, which sends signals to processes on the system.
Give examples of Standard signals.
SIGHUP SIGINT SIGKILL SIGTERM SIGSTOP SIGCONT
Define: SIGHUP
hangup - sent to process when you logout or if your terminal is disconnected
Define: SIGINT
Interrupt: sent when you press ^C
Define: SIGKILL
Kill: immediate termination (Can not be trapped or ignored by a process)
Define: SIGTERM
Terminate: request to terminate; (Can be trapped or ignored by a process)
Define: SIGSTOP
Stop (suspend): sent when you press ^Z
Define: SIGCONT
Continue: resume suspended process; usually sent by the fg or bg commands
If no single is specified in the kill command, by default, what happens?
SIGTERM is sent - Requests that the process to exit
Which processes can be intercepted or even ignored?
All signals except of SIGKILL and SIGSTOP.
SIGKILL and SIGSTOP are only seen by the ______
The host system’s kernel, providing reliable ways of controlling the execution of processes.
What are the requirements for a process to successfully send a signal to another?
Essentially, for a process to successfully send a signal to another, the owner of the signalling process must be the owner of the receiving process or be the super-user
Can Ctrl-C interrupt key abort a background process?
No, only a kill command can. Ctrl-C can only abort a foreground process.
How do you specify a job ID in the command line?
%4 (where “4” is a hypothetic job ID)
What does the command “bg” mean?
Lists background jobs. Without job number means, the most recent stopped job.
What does the fg command do?
Transfer a process from the background to the foreground and make it the current process.
If a background task sends output to the standard output, or standard error, and you do not redirect it - what happens?
output appears on the screen, even if you are running another job
If a background task requests input from the standard input, and you have not redirected the standard input - what happens?
Depends on the shell type:
- bourns-style shells: supplies a null string
- Suspends the job and waits for you to give it input.