Edaf35: Operating Systems: Processes, Threads
Edaf35: Operating Systems: Processes, Threads
MODULE 3
PROCESSES, THREADS
CONTENTS
MODULE 3
execute
PROGRAM
DISK
PROCESS STATE
PROCESSES
PID
• processes migrate among different queues: job queue — all processes, ready
queue — waiting to run, device queue — waiting for a particular I/O device
more in Module 5
• Create
shared memory segment (“everything is a file in UNIX”):
shm_fd = shm_open(name, O_CREAT | O_RDWR, 0666);
— other processes use it to open an existing segment.
• Set the size of the object: ftruncate(shm_fd, 4096);
• Map it to memory: STANDARD
ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, shm_fd, 0); FILE
OPERATIONS
• Write to/read from the shared memory:
sprintf(ptr, "Writing to shared memory”);
• Remove the segment: shm_unlink(name);
‣ wait indefinitely
• send and receive — flexible
‣ wait at most n milliseconds
‣ return immediately
• Sockets
• Pipes
focus of Networking and Web Programming courses — see book for more details
SOCKET COMMUNICATION
PROCESSES
SOCKETS IN JAVA
PROCESSES
A Date Server
• Three types of sockets:
• choices:
uni- or bi-directional?
full or half duplex?
parent—child based or not? Rd Wr
local or network based?
thread
context
WHY MULTIPLE THREADS?
THREADS
• Responsiveness – part of a process can block while other parts still run (e.g. GUI)
• divide activities
• balance
• handle dependencies
1
speedup ≤ 1−S
S+ N
AMDAHL’S LAW
POSIX THREADS
WINDOWS THREADS
JAVA THREADS
VIRTUALLY ALL
Kernel Space MANAGED HERE = KERNEL LEVEL GENERAL PURPOSE
OS
MULTITHREADING MODELS
MAPPING THREADS
User Space
Kernel Space
1 many-to-one 2 one-to-one 3 many-to-many
text book
THREAD POOLS
OPENMP
others
GRAND CENTRAL DISPATCH
• scheduler activation — scheme for communicating between u-thread lib and kernel
• upcalls — kernel informs u-thread lib about k- events (e.g.“LWP about to block”)
WINDOWS THREADS
OS EXAMPLES
• kernel-level, one-to-one