Professional Documents
Culture Documents
Ch3 Processes 6
Ch3 Processes 6
Process Concept
Process Scheduling
Chapter 3: Processes
Operations on Processes
Interprocess Communication
Examples of IPC Systems
Communication in Client-Server Systems
Objectives
3.3
Process in Memory
3.5
3.4
Process State
Process Concept
3.2
3.6
3.7
3.9
3.8
3.10
3.11
3.12
Schedulers
Long-term scheduler (or job scheduler) selects which
3.13
3.14
Schedulers (Cont)
Short-term scheduler is invoked very frequently (milliseconds)
(must be fast)
Long-term scheduler is invoked very infrequently (seconds,
minutes)
(may be slow)
3.15
Context Switch
3.16
Process Creation
When CPU switches to another process, the system must save the state of
the old process and load the saved state for the new process via a context
switch
Context of a process represented in the PCB
switching
Time dependent on hardware support
Execution
3.17
3.18
Process Creation
Address space
UNIX examples
exec system call used after a fork to replace the process memory
space with a new program
3.19
3.20
int main()
{
pid_t pid;
/* fork another process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
exit(-1);
}
else if (pid == 0) { /* child process */
execlp("/bin/ls", "ls", NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait (NULL);
printf ("Child Complete");
exit(0);
}
}
3.21
Process Termination
delete it (exit)
Information sharing
Computation speedup
Modularity
If parent is exiting
Convenience
Interprocess Communication
3.22
3.23
Shared memory
Message passing
3.24
Communications Models
Cooperating Processes
Independent process cannot affect or be affected by the execution of
another process
Cooperating process can affect or be affected by the execution of another
process
Advantages of process cooperation
3.25
Producer-Consumer Problem
Paradigm for cooperating processes, producer process
Information sharing
Computation speed-up
Modularity
Convenience
3.26
#define BUFFER_SIZE 10
typedef struct {
...
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
Solution is correct, but can only use BUFFER_SIZE-1 elements
3.27
Bounded-Buffer Producer
3.28
while (true) {
/* Produce an item */
buffer[in] = item;
return item;
3.29
3.30
Implementation Questions
processes?
What is the capacity of a link?
Is the size of a message that the link can accommodate fixed or variable?
Is a link unidirectional or bi-directional?
3.31
Direct Communication
Processes must name each other explicitly:
3.32
Indirect Communication
Messages are directed and received from mailboxes (also referred to as
ports)
3.33
Indirect Communication
3.34
Indirect Communication
Mailbox sharing
Operations
destroy a mailbox
Solutions
3.35
3.36
Synchronization
Buffering
ways
3.37
3.38
port_allocate()
When done a process can detach the shared memory from its address
space
shmdt(shared memory);
3.39
3.40
The server creates two private communication ports and returns the
handle to one of them to the client
The client and server use the corresponding port handle to send
messages or callbacks and to listen for replies
3.41
3.42
Sockets
161.25.19.8
Communication consists between a pair of sockets
3.43
Socket Communication
3.44
on networked systems
Stubs client-side proxy for the actual procedure on the server
The client-side stub locates the server and marshalls the parameters
The server-side stub receives this message, unpacks the marshalled
3.45
Execution of RPC
3.46
remote object
3.47
3.48
Marshalling Parameters
End of Chapter 3
3.49