CSC320 chapter7 - Processes A process is an abstraction for...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Processes b A process is an abstraction for sequence of operations that implement a computation/program. A process may be manipulated, suspended, scheduled and terminated. b Process is a unit of work in a modern computer. b Process Types: s OS processes executing system code program. s User processes executing user code program. Processes are executed concurrently with CPU multiplexing among them.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Process states Possible process states s Running (occupy CPU) s Blocked s Ready (does not occupy CPU) s Other states: suspended, terminated Transitions between states Question: in a single processor machine, how many processes can be in running state?
Background image of page 2
3 Five-state process model • Add states for creating and deleting process. • Add transitions Timeout, Dispatch, Event Occurs. Events are: I/O Synchronization
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Concurrent processes b Two processes run concurrently (are concurrent) if their flows overlap in time. Otherwise, they are sequential. b Examples: Sequential: B & C
Background image of page 4
5 Process control Objectives b Process control: Process creation, process execution, process termination. b Process properties b e.g., ID’s. b Related functions b e.g., system()
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Process identifiers b Process Identifiers Process ID – a nonnegative unique integer b Special Processes b PID 0 – Swapper (i.e., the scheduler) Kernel process, part of kernel b PID 1 – init responsible for bringing up a Unix system after the kernel has been bootstrapped. Program files for this process: (/etc/rc* & init or /sbin/rc* & init). Init is a user process with superuser privileges b PID 2 - pagedaemon responsible for paging Kernel process
Background image of page 6
7 Process identifiers, cont. #include <sys/types.h> #include <unistd.h> pid_t getpid(void); Returns: id of caller pid_t getppid(void); Returns: id of parent uid_t getuid(void); Returns: real uid of caller uid_t geteuid(void); Returns: effective uid of caller gid_t getgid(void); Returns: real gid of caller gid_t getegid(void); Returns: effective gid of caller None of them has an error return code
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Creating a process: Fork b Fork duplicates a process so that instead of one process you get two--- But the code being executed doesn’t change. b Fork returns b 0 if child b -1 if fork fails b Child’s PID if parent process b Child gets new program counter, stack, file descriptors, heap, globals, pid.
Background image of page 8