OperatingSystem CH3 Process
Chapter 2
operating systems provide an environment for execution of programs and services to programs and users
one set of operating-system services provides functions that are helpful to the user:
- User Interface: almost all operating systems have a user interface varies between CLI(command-line), GUI(Graphics user interface), Batch
- Program execution: The system must be able to load a program into memory and to run that program, end execution, either normally or abnormally(indicating error)
- I/O operation: a running program may require I/O, which may involve a file or an I/O device
OS service provides functions that are helpful to user
- File-system manipulation
- Communications
- Error detection
Efficient operation
- Resource allocation
- Accounting
- Protection and security
- protection
- security
CLI
- sometimes implemented in kernel, sometimes by systems program
- sometimes multiple flavors implemented - shells
- primarily fetches a command from user and executes it
- sometimes commands built-in sometimes just names of programs
- if the latter, adding new features doesn’t require shell modification
GUI
- user-friendly desktop metaphor interface
- usually mouse, keyboard, and monitor
- icons represent files, programs, actions, etc
- various mouse buttons over objects in the interface cause various actions(provide information, options, execute function, open directory(known as a folder))
- invented at xerox parc
- many systems now include both CLI and GUI interfaces
- microsoft windows is GUI with CLI command shell
- apple mac os x is “aqua” gui interface with unix kernel underneath and shells available
- unix and linux have CLI with optional GUI interfaces(CDE,KDE,GNOME)
Touchscreen interfaces
- mouse not possible or not desired
- actions and selection based on
System calls
- Programming interface to the services provided by the OS
- Typically written in a high-level language(C or C++)
- Mostly accessed by program via a high-level application Programming interface(API) rather than direct system call use
- Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems(including virtually all versions of UNIX, Linux and Mac OS X), and Java API for the Java virtual machine(JVM)
- note that the system-call names used throughout this text are generic
System call parameter passing
- often, more information is required than simply identity of desired system call
- Exact type and amount of information vary according to OS and call
- Three general methods used to pass parameters to the OS
- simplest: pass the parameters in registers
- parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register
- parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system
- block and stack methods do not limit the number or length of parameters being passed
#Types of system calls
- File management
- Device management
- Information maintenance
- Communications
- Protection
Processes: a program in execution
Heuristic Algorithm(Time constraint)
Batch: job
Concurrent: task
Process State:
Ready - running - waiting -> this cycle called MIX
The degree of multiprogramming(The number of process in the MIX)
Controlling the degree of Programming CPU utilization
Purpose of OS
- participate
Process creation
- PID = fork()
Parent process can create child processes
And Child also can create child processes
Where a Process creates New Process
- The parent continues
- The parent waits
Address Space
- The child is a duplicate of the parent
- The child has a new program loaded
Terminate
- Parent is in control
- parent can kill a child
- go to terminate status -> leave the system
- Casacading termination
- kill whole family
- Orphan
- kill only parent
- since they don’t have parents, they goes to ‘init’ process as their parent
- Zombie
- who is in the process of dying
Windows Example
if you erase waiting, parent will do his work not depends on child’s work.
Unix Example
Here, if you put execlp("/bin/ls","ls",NULL);
children will be terminated so printf("Child \n");
is not printed
Windows:
Child is becoming new stuff without duplicating
Unix:
Child is duplicating parent and becoming new stuff
Interprocess Communication (concurrency)
- Independent Process
- Not affect or is affected by other processes
- Cooperating Process
- If it can affect other processes
- Shared Data
Reasons for cooperation
- Information Sharing
- Computational Speed-up(Need “parallel” execution)
- Modularity
- Convenience
How do processes communicate
Processes require an interprocess communication method(IPC)
- Shared Memory
- Faster(Usually no system[after setup] calls)
- Message Passing
- Exchanging small amounts of data
- Easier to implement in distributed systems (Usually done using system calls)
Note: Multiprocessor core system may have issues with shared memory because of ‘casche coherency’
Shared Memory
- Establish a register of shared memory
- Usually it is placed in the process that creates the shared space
- “No more OS support required”
- Responsibility to use “correctly” (User Processes)
Message Passing
- The OS provides a message passing facility
- Communicate / Synchronize
- No shared memory
Direct/ Indirect Communication
- Direct: Each process must “explicitly” name the other processes
- Send(P,msg)
- Receive(Q,msg)
- Properties
- process only needs to know the identity of other(Link is setup automatically)
- A link is setup with exactly two processes
- Only one(1) link between a pair of processes
- Symmetric in addressing(Know each other)
- A symmetric(Only the sender nows)
- Send(P,msg)
- Recieve(id,msg)
- Direct leads to Head-Coded
- Indirect: Message sent and recieved using mailbox supported by port
- Send(A,msg) ; A is mailbox
- Receive(A,msg)
- Properties
- If process share a mailbox then there is a link between them
- Can be used to link more than two(2) processes
- A pair of processes could have more than one(1) link
- Handling conflicts
- Allow only links of two processes
- Allow only 1 process at a time to execute a receive
- Allow the OS to select “arbitrarily”
Who “owns” the mailbox
- If owned by process:
- it is part of its address space
- can only receive
- It is owned by the OS
- process has to be able to request a mailbox
-
send receive - delete the mailbox
- it is part of its address space
Synchronization
- Send - msg passing
- Blocking(synchronizing) send(sync)
- The sender blocks until the message is recieved -> mailbox or process
- Non Blocking (async)
- Blocking(synchronizing) send(sync)
- Receive()
- Blocking
- Non Blocking
- If both are blocking “Rendevous”
- Buffering : talk about implementation
- Zero capacity: Length is zero
- Bounded capacity: Finite Length N
- Unbounded capacity: (sender never blocks)
Socket
- Should know what Remote procedure call
- we have to know the socket that i send it to
- Problem is many clients want to access server it is dynamic
- Match maker
- Usually in the server side
Pipe IPC
- One of the first IPC mechanisms in early UNIX
- Pipe
- Unidirectional?
- Half duplex or full duplex?
- Is it local network?
- One way(Ordinary pipe)
- Named pipe (persistent so we can use it again don’t need parent and child relationship