Professional Documents
Culture Documents
• Process Concept
• Process Scheduling
• Operation on Processes
• Cooperating Processes
• Interprocess Communication
• CPU registers: The registers very in number and type, depending on the
computer architecture. Along with the program counter, the state information must
be saved when an interrupt occurs, to allow the process to be continued correctly
afterword.
• Some system does not user long term scheduler. For example:
time-sharing system such as UNIX often have no long term
scheduler but simply put every new process in the memory for
the short term shceduler.
• These operating systems may introduce an additional,
intermediate level of scheduling.
• These medium term scheduler removes processes from memory
and thus reduces the degree of multiprogramming.
• At some later time, the process can be reintroduced into memory
and its execution can be continued where it left off.
• Address space
– The child process is a duplicate of the parent process.
– Child has a program loaded into it.
• UNIX examples
– fork system call creates new process
– execve system call used after a fork to replace the process’
memory space with a new program.
• In Unix, all processes are created with the system call fork().
This is without exception. What fork() does is the following:
• It creates a new process which is a copy of the calling process.
That means that it copies the caller's memory (code, globals,
heap and stack), registers, and open files. The calling process
returns from fork() with the pid of the newly created process
(which is called the "child" process. The calling process is called
the "parent" process). The newly created process, as it is a
duplicate of the parent, also returns from the fork() call (this is
because it is a duplicate -- it has the same memory and registers,
and thus the same stack pointer, frame pointer, and program
counter, and thus has to return from the fork() call). It returns
with a value of zero. This is how you know what process you're in
when fork() returns.
main()
{
int i;
printf("simpfork: pid = %d\n", getpid());
i = fork();
printf("Did a fork. It returned %d. getpid = %d. getppid = %d\n", i,
getpid(), getppid());
}
• Shared data
var n;
type item = … ;
var buffer. array [0..n–1] of item;
in, out: 0..n–1;
• Producer process
repeat
…
produce an item in nextp
…
while in+1 mod n = out do no-op;
buffer [in] :=nextp;
in :=in+1 mod n;
until false;
• Consumer process
repeat
while in = out do no-op;
nextc := buffer [out];
out := out+1 mod n;
…
consume the item in nextc
…
until false;
• Solution is correct, but can only fill up n–1 buffer.