0% found this document useful (0 votes)
2 views

Lab 1 Processes

A process is an instance of a computer program in execution, utilizing system resources like CPU and RAM. Processes can be created through forking, with parent and child processes executing concurrently, and can be categorized into running, waiting, stopped, and zombie states. The document also discusses process management commands in Unix, including moving processes between foreground and background, viewing processes, and terminating them.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab 1 Processes

A process is an instance of a computer program in execution, utilizing system resources like CPU and RAM. Processes can be created through forking, with parent and child processes executing concurrently, and can be categorized into running, waiting, stopped, and zombie states. The document also discusses process management commands in Unix, including moving processes between foreground and background, viewing processes, and terminating them.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Lab : Process Management

What is a process?

 A process is an instance of a computer program


being executed using code and instructions
 Each process uses system resources like CPU or
RAM to complete the specific tasks
Process Concept
 Process – a program in execution; process execution
must progress in sequential fashion.
 Textbook uses the terms job and process almost
interchangeably.
 A process includes: text
global data
 Program counter heap
 Stack (local variables)
 Data section (global data)
 Text (code)
 Heap (dynamic data)
 Files (cin, cout, cerr, other file descriptors) stack

3
Process Control Block
Process ID
UID GID EUID EGID
Directory Entry
TTY
code
 Process ID
 CPU status
Signal Dispatch
Table
Memory Map heap
 Memory limits
0 stdin priority
1 stdout
2 stderr
3
Intr. mask
registers  List of open files
stack
CPU Status
File Descriptors

trek.txt

4
Process Status
user
user mode running memory
system call
system call interface Interrupt return
kernel mode
interrupt kernel kill/exit
Interrupt return
zombie
running PCB 5

exit( ) signal
sleep
schedule
wait queue ready queue

PCB 3 PCB 4 asleep wakeup ready PCB 1 PCB 2

memory
disk
new
process
program

5
Process Scheduling
Short-term scheduler: picks up a process from
ready queue every 100ms

Long-term
scheduler: swaps
I/O waiting
processes
in and out of
memory

CSS503 Chapter 3: Processes 6


Process Creation
 Parent process creates children processes.
 Resource sharing
 Resource inherited by children: file descriptors, shared memory
and system queues
 Resource not inherited by children: address space
 Execution
 Parent and children execute concurrently.
 Parent waits by wait system call until children terminate.
 UNIX examples
 fork system call creates new process.
 execlp system call used after a fork to replace the process’
memory space with a new program.

CSS503 Chapter 3: Processes 7


Backgrounrd & Foreground
Processes
 A foreground process is any process which is not
continuously running and it waiting on something
like user input
 A background process is something that is
continually running and does not require any
additional input
 Can someone name examples of each?
Moving a Process to the
Background
 When executing commands on the command line,
there is usually some output that is displayed on
the terminal
 If you move a process to the background, the
output will not be shown
Background Process Example

 Usually, when you download a file from the


command line, the status is displayed on the
terminal
 To move a process to the background all you have
to do is add an ampersand (&) at the end of the
command
 Wget http://releases.ubuntu.com/18.04.2/ubuntu-18.04.2-desktop-
amd64.iso_ga=2.142658160.410030815.1551071806-1676866732.1550780350 &

 Now this will be moved to the background


Moving back to the Foreground

 To move a process back to the foreground, use the


following steps:
 Use the jobs command to identify the job number
of the background process
 Then use the fg command to bring it back with the
following syntax
 fg [job number]
How do Processes Actually
Work?
 In the Unix operating environment, processes are
created by a method called “forking”
 Forking is when the OS duplicated a process
 The original process is called the parent process
 And the new process is the child process
Different Types of Processes

 There are four types of processes:


 Running: current process that is being executed
in the operating system
 Waiting: process which is waiting for system
resources to run
 Stopped: process that is not running
 Zombie: process whose parent processes has
ended, but the child process is still in the
process table
Viewing Processes

 Two commands you can use to view the process


from the command line: ps and top
 To view all the processes with ps, use ps -ef

ps -ef top
Ending a Process In Linux

 Sometimes you need to end a program or process from the command


line. Use the following steps:

1. Locate the process id [PID] of the process/program you want to kill


2. Use the kill command with the following syntax: kill [PID]
3. If the process is still running, do the following: kill -9 [PID]
4. The -9 is a SIGKILL signal telling the process to terminate
immediately
Ending All Process

 You can use the killall command to kill multiple


processes at the same time
 Syntax: killall [options] PIDs
 Or you can use pkill –u [username] to kill all
processes started by [username]

You might also like