Wednesday, February 3, 2010
process states
1. What are the process states in Unix?
As a process executes it changes state according to its circumstances. Unix processes have the following states:
Running : The process is either running or it is ready to run .
Waiting : The process is waiting for an event or for a resource.
Stopped : The process has been stopped, usually by receiving a signal.
Zombie : The process is dead but have not been removed from the process table.
Unix/Linux
Create a new (child) process – fork();
Allocates new PCB
Clones the calling process (almost)
Copy of parent process address space
Copies resources in kernel (e.g. files)
Places PCB on Ready queue
Return from call
0 for child
child PID for parent
The OS maintains a collection of process state queues
typically one queue for each state – e.g., ready, waiting, …
each PCB is put onto a state queue according to its current state
as a process changes state, its PCB is unlinked from one queue, and linked to another
Process state and the queues change in response to events – interrupts, traps
This a a brief introduction to a facet of system security which will be covered in more detail in the future
Users are given privileges by the system administrator
Privileges determine what rights a user has for an object.
Unix/Linux - Read|Write|eXecute by user, group and “world”
WinNT – Access Control List
Processes “inherit” privileges from use
Starting another program
Unix – int exec (char *prog, char **argv)
Check privileges and file type
Loads program “prog” into address space
Initializes context – e.g. passes arguments (*argv)
Place PCB on ready queue
Windows/NT – combines fork & exec
CreateProcess ( 10 arguments )
Not a parent child relationship
Note – privileges required to create a new process
The OS maintains a collection of process state queues
typically one queue for each state – e.g., ready, waiting, …
each PCB is put onto a state queue according to its current state
as a process changes state, its PCB is unlinked from one queue, and linked to another
Process state and the queues change in response to events – interrupts, traps
Processes – Switching:
When a process is running, its hardware state is in the CPU – PC, SP, processor registers
When the OS suspends running a process, it saves the hardware state in the PCB
Context switch is the act of switching the CPU from one process to another
timesharing systems may do 100s or 1000s of switches/sec
takes 1-100 microseconds on today’s hardware
Process start
When the system boots
By the actions of another process
By the actions of a user
By the actions of a batch manager
Processes end
Normally – exit
Voluntarily on an error
Involuntarily on an error
Terminated (killed) by the actions a user or a process
pical PCB contains:
Tyexecution state
PC, SP & processor registers – stored when process is made inactive
memory management info
Privileges and owner info
scheduling priority
resource info
accounting info
Processes in the OS – Representation::
To users (and other processes) a process is identified by its Process ID (PID)
In the OS, processes are represented by entries in a Process Table (PT)
PID “points to” a PT entry
PT entry = Process Control Block (PCB)
PCB is a large data structure that contains or points to all info about the process
Linux - defined in task_struct see include/linux/sched.h – over 70 fields
NT – defined in EPROCESS – about 60 fields
A process in Unix or Windows comprises (at least):
an address space – usually protected and virtual – mapped into memory
the code for the running program
the data for the running program
an execution stack and stack pointer (SP)
the program counter (PC)
a set of processor registers – general purpose and status
a set of system resources
files, network connections, privileges, …
PROC TABLE:
SLOT ST PID PPID PGRP UID PRI CPU EVENT NAME FLAGS
0 s 0 0 0 0 95 0 runout sched load sys lock nwak
1 s 1 0 0 0 66 1 u init load
2 s 2 0 0 0 95 0 kspt1+0x10bbdc vhand load sys lock nwak nxec
3 s 3 0 0 0 81 0 kspt1+0xfe64c bdflush load sys lock nwak nxec
4 s 4 1 1 0 95 0 vm_dma_end+0x11cc8 kmadaemon load sys lock nwak nxec
5 s 5 1 11 0 95 0 kspt1+0xcbdc8 htepi_daemon load sys lock nwak nxec
6 s 6 1 16 0 95 22 pbintrpool strd load sys lock nwak nxec
7 s 289 1 289 0 73 0 proc+0x968 ksh load
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment