Skip to content

TEC-2014092195/producer-consumer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Producer - Consumer

The purpose of this project is to experiment with shared memory between heavyweight processes.

Usage

Creator

It's responsible for creating the shared circular buffer, and to initialize all the associated control variables (semaphores, flags, counters, etc.)

Use the next command in order to run the Creator:

./cycle/creator [-n buffer_name] [-s buffer_size] &

The value of buffer_size must be an integer. A specific example looks like this:

./cycle/creator -n shm_shared_buffer -s 10 &

Producer

It's a family of processes from the same implementation, they link to the buffer created by the Creator. They will produce messages that will be put in the circular buffer, this will be done with random sleeping time.

The messages will look like this: 21412-Date: 2020/3/15 Time: 13:12:43-2

21412: it's the PID of the Producer

Date: 2020/3/15 Time: 13:12:43: it's the exact date and time when the message was produced.

2: it's a random key value from 0 to 4.

Use the next command in order to run the Producer:

./cycle/producer [-n buffer_name] [-m mean_of_random_time] &

The value of buffer_name must be the same used in the Creator. A specific example look like this:

./cycle/producer -n shm_shared_buffer -m 1 &

Consumer

It's a family of processes from the same implementation, they link to the buffer created by the Creator. They will read messages from the circular buffer previously created, this will be done with random sleeping time.

Use the next command in order to run the Consumer:

./cycle/consumer [-n buffer_name] [-m mean_of_random_time] &

The value of buffer_name must be the same used in the Creator. A specific example look like this:

./cycle/consumer -n shm_shared_buffer -m 1 &

Killer ☠️

Program that cancels all the processes by sending special messages to the Consumer through the shared circular buffer, and by turning off a bit flag that indicates if the Producers should write messages.

Use the next command in order to run the Killer:

./cycle/killer [-n buffer_name] &

The value of buffer_name must be the same used in the Creator. A specific example look like this:

./cycle/killer -n shm_shared_buffer &

Notes

  • The & at the end of the commands is for returning the console after running the instruction.
  • The Producer, Consumer, and Killer all of them require to run the Creator before to run any of them.

Confessions 🙈

  • The circular buffer was implement in a struct, it has a well known size of 4096, however we simulate the action of setting the size of the buffer by the control provided by the semaphore, so for the user the buffer will have the size they set as long as it's not bigger than 4096. In fact, the index of written messages never is going to be bigger than size.

Developed by

Kevin Hernández, Steven Solano, Elisa Argueta, and Jose Pablo Araya

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •