C Sleeping Barber

0 Gary Griffith · October 11, 2015
I very new to C and programming. I have to write a program that simulates the Sleeping Barber problem (using processes).  I am having a huge amount of trouble getting anywhere.  Can anyone help?

Post a Reply

Replies

Oldest  Newest  Rating
+1 Jon Z. · October 11, 2015
You can use fork. here is a simple example.


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main (int argc, char *argv[])
{

int pid;

   pid = fork();
     
   if (pid == 0){
       printf("I am the child with PID: %d\n", getpid());        
   }
else{
printf("I am the parent of a child with PID: %d\n", pid);
}

   return 0;
}
0 Linguist Llama · October 15, 2015
Where is your code?

What are the error and/or warning messages, if any? What do you think they mean?

What is going wrong with your code?
  • 1

C

107,188 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator