To write a c program in UNIX environment to implement the producer – consumer relationship. Operating System (OS) LAB in LINUX environment
Producer – consumer relationship is a type of interprocess communication. if one process a producer, is generating information that a second process, a consumer is using. They communicate by a single shared integer variable, number buffer. The producer does some calculations and then writes the result into number buffer; the consumer reads the data from number buffer and prints it. It is possible that the producer and consumer processes could run quite nicely in tandem, or their speeds could be grossly mismatched. if every time the producer deposits a result in number buffer the consumer immediately reads it and prints it, then the printed output will faithfully represents the stream of numbers generated by the producer.
But if the speeds of the processes are mismatched i.e., if the consumer is operating faster than the producer, the consumer could read and print the same number twice before the producer deposits the next number. if the producer is operating faster than consumer, the producer could overwrite its previous results before the consumer has had a chance to read it and print it; a fast producer could in fact do this several times so that many results would be lost.
• Declare the function process1 and process2.
• Initialize two variables and pass it to first function.
• Generate the number up to value z.
• Generate the number using second function generated number are displayed on screen.
• Terminate the program.
PROGRAM SOURCE CODE
int pro1(int a,int z)
int pro2(int a,int z)
int pro1(int a,int z);
int pro2(int a,int z);
Thus the c program to implement a producer- consumer relationship was written and executed successfully.