ICS 431-Ch3-Process Management
ICS 431-Ch3-Process Management
Weeks 4-5
• Yes, two concurrent instances of processes can share the code section of
the parent process.
– Example: Opening two word files on the same machine, both will use the
same code section while each will have its own data and sate.
• Why? to maximize the memory utilization.
• The OS must know more information about the process to manage it.
• PCB (Process Descriptor in Linux) is the data structure that stores the following
information about the process:
– Process ID (a unified name assigned by the OS, i.e. an integer or a table
index, etc.),
– Process State (the current state, such as new, running, waiting, ready,
terminated),
– Owner (identified by the owner’s internal identification, such as user’s login
name),
– Program Counter (the address of the next instruction to be executed by the
process),
– CPU Registers (contents of , accumulator register, index registers, stack
pointers, condition-code bits and other general purpose registers)
– CPU Scheduling Information (process priority, pointers to scheduling queues
and other scheduling parameters),
– Process Privileges (Processes are granted privileges in terms of the memory
that may be accessed and the types of instructions that may be executed),
– Parent Process (a pointer to the PCB of the parent process),
• Some of the PCB contents are machine specific and others are OS
specific, i.e.
Processor state
Program counter (PC)
Machine specific
Registers
Memory limits (Base & Limit)
Process number
Process state
OS specific
List of open files
…
• In a single processor system, if one process can run at a time, this makes
poor CPU utilization.
• The multiprocessing OS is recommended on single processor machines.
• The objective of multiprocessing is to maximize CPU utilization by
concurrent processing:
– Alternate the execution of more than one process.
• Concurrency can be achieved by switching the processor among several
processes, i.e. I/O and Computing Instructions interleaving.
• Switching the CPU from one process to another is called Context Switch.
Idle
3. User and kernel mode switching: When a transition between user mode
and kernel mode is required in an OS. Some OSs may not consider a mode
transition itself a context switch.
Ready Queue
Job Queue
Each PCB includes a pointer field that points to the next PCB in the ready queue.
Medium-term
Long-term
enter end
Job Ready
CPU
queue queue
Short-term
I/O waiting
Active I/O
queue(s)
Long-term
enter Job Ready end
CPU
queue queue
Short-term
I/O waiting
Active I/O
queue(s)
Medium-term
Long-term
enter end
Job Ready
CPU
queue queue
Short-term
I/O waiting
Active I/O
queue(s)
• The mid-term scheduler exists in all systems with virtual memory support, temporarily
swaps out processes from the main memory and places them on virtual memory or vice
versa.
• It may decide to swap out a process:
– Has not been active for some time,
– Has a low priority,
– With high page fault frequently,
– Taking up a large amount of memory in order to free up main memory for other
processes, swapping the process back in later when more memory is available, or
– etc….
– Create a process by running a program (writing its name then press enter key from the
CLI.)
– You can run many processes either foreground or background concurrently.
– You can also move the process from foreground to background by the commands fg
process name or bg process name but you need to close the process CTRL+Z first.
– Use top command to tell the user about all the running processes in Linux, or tasklist in
windows. It displays:
– Where, PID is the user ID number. User is the owner of the process. PR is the priority
(20 high to -20 low).
– NI is the nice value (priority index and can be changed like priority) of the process,
VIRT is the amount of the virtual memory taken by the process in KB.
– RES is the physical memory used in KB.
– SHR is the shared memory used.
– S is the status of the process (sleeping/S or running/R or traced/stopped/T or …
– %CPU and %MEM are the % of CPU time and memory used. TIME+ is the total time.
Dr. Tarek Helmy, ICS-KFUPM 25
Process Management in Unix/Linux
Basic commands of process management in Unix: (i.e. creation, execution, waiting, exiting, killing)
– fork() command creates a child process that inherits copies of all parent’s variables.
– exec() command allows a process to “load” a child and start executing it.
– exit() command causes normal process termination (closes all open files, connections, de-
allocates memory, de-allocates most of the OS structures supporting the child process), and
checks if the parent is alive then it holds the result value until the parent requests it.
– wait() command puts the parent to sleep waiting for a child’s result.
– ptrace() command allow a parent process to observe and control the execution of a child
process.
– nice() command can be used to reduced the priority of a process and thus be ‘nice’ to the
other processes.
– sleep(), command delays the execution start time of a process by some number of seconds
that the user specifies.
– kill() <pid> command will terminate a process with the process id <pid>. The pid of a
process can be obtained using the ‘ps’ command.
– ps command gives information about the process including the pid, terminal name, time of
creation and name of the process, etc…
– ps ux to display the status of all the processes under this user, or ps PID for
only one process. You can get the PID of the process by pidof process
name.
– kill command terminates a process running on the Linux machine. i.e. kill
PID, or taskkill /PID in windows
– renice changes the priority of a process (changes from -20 to 19, the default
value is 0). Its syntax is nice –n nice-value process-name.
– free gives us the details of the free RAM space on the system.
• Purpose of IPC:
– Data Transfer
– Sharing Data
– Event notification
– Synchronization
– Mutual Exclusion ; assure that only one is executing at a time
– Process Control; notification through Signals (i.e. wait, exec,
sleep, kill)
Producer Consumer
Process Shared Buffer Process
P C
From time to time, the producer places an item into the buffer.
The consumer removes an item from the buffer.
Careful synchronization/coordination is required.
The consumer must wait if the buffer is empty.
The producer must wait if the buffer is full.
Typical solution would involve a shared variable called count
to monitor the buffer size.
Buffered
Items
Out: Consumer
• Using Sockets
• Socket: a door between a process and a Transmission Protocol (i.e. UDP or TCP):
• UDP (User Datagram Protocol) [does not guarantee a reliable transfer of bytes] it
offers a limited amount of service when messages are exchanged between
computers in a network that uses the Internet.
• TCP guarantees delivery of data and also guarantees that packets will be delivered
in the same order in which they were sent.
controlled by
controlled by process
process application
application
socket developer
developer socket
TCP with TCP with controlled by
controlled by
buffers, buffers, operating
operating internet
variables variables system
system
host or host or
server server
message
client server
other ports
Internet address = 138.37.94.248 Internet address = 138.37.88.249
Process 1 Process 2
TCP TCP
IP 164.86.5.20 IP 161.25.19.8
Ethernet Ethernet
Request Reply
Rendezvous
• Client makes procedure call (like a local procedure call) to the client stub.
• A stub is a piece of code that converts parameters passed between the
client and the server during a remote procedure call (RPC).
• Client Stub locates the server and the port on the server.
• Client Stubs take care of packaging arguments and sending messages.
• Packaging the parameters is called “marshalling”.
• The server-stub receives the message, unpacks the marshaled parameters,
invokes the procedure on the server and then returns the value.
Procedure
Procedure
JVM JVM
• The server’s object must register itself under some name where it
can be reached.
• Under RMI, this is done with the RMI Registry, a separate process
that must be running, usually on the server machine.
• Once an object has been registered, any other objects can use the
Object Registry to obtain access to its methods remotely using the
name of the object.
JVM JVM
Stub Skeleton
• Stub locates the server, sends the parcel to the skeleton of the server.
• The skeleton is responsible for un-marshalling the parameters and invoking the
desired method on the server.
• The skeleton then marshals the return value into a parcel and send it to the Stub.
• The stub receives this message, unpacks the marshaled return value and passes it
to the client.
• Client /Server?
– RPC is typical client/server application
• Server defines procedure.
• Client invokes it.
– But RMI provides more flexible way.
• Dynamic class loading
• Safe & Security?
– RPC Security mechanism
• Operating System based
– RMI Security mechanism
• Uses Java’s built in Security features
• A security manager has to be installed before RMI can be used
• Object -Oriented?
– RPC is not Object-Oriented.
– RMI is Object-Oriented.
• Language independent?
– RPC was designed for a heterogeneous environment. Use eXternal
Data Representation (XDR) protocol to standardizes the representation
of data.
– RMI was designed for JAVA to JAVA environment.
Thank you
Any Questions?