last os
Process Creation:
Processes are created with the fork system call.
So what is fork() ?
Producer Consumer code using semaphore:
video tutorialsemaphore S=1;
semaphore E=n;
semaphore F=0;
void producer()
{
while (T)
{
produce();
wait(E);
wait(S);
append();
signal(S);
signal (F);
}
}
void consumer()
{
while(T)
{
wait(F);
wait(S);
take();
signal(S);
signal (E);
use();
}
}
Reader writer problem :
Structure of writer process:
while(true)
{
wait(wrt);
//writing is performed
signal(wrt);
}
Structure of reader process:
while (true)
{
wait(mutex);
readcout++;
if(readcount==1)
{
wait(wrt);
}
signal(mutex);
//reading is perform
wait(mutex);
readcout--;
if(readcout==0)
signal(wet);
signal(mutex);












Comments
Post a Comment