Operating system LINUX

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Operating system LINUX
# 1  
Old 04-11-2010
Operating system LINUX

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
Write a C program that accepts 3 parameters. Each parameter indicates the quantity of product to be
produced. Each product will be produced in different production line. Ready products will be placed
in a buffer area located at the end of each production line. Packaging workers will pack the products
into boxes. Information of each production line as follow:
Production line A: product ready in 1-2 minutes, buffer capacity: 12 units
Production line B: product ready in 2-3 minutes, buffer capacity: 6 units
Production line C: product ready in 1-2 minutes, buffer capacity: 24 units
There are currently 2 packaging workers available. Each worker needs 2 minutes to pack 6 units of
product into a box. The production line will be temporary suspended if the buffer area is full of
product. The operation will continue when the worker has taken 1 unit of product from the buffer
area.
Simulate the operation of production line and the packaging workers by using threads and
appropriate semaphores. There are at least 5 threads, but you may use additional thread if it is
necessary. You have to decide how the workers select the product to pack. Assume that 1 second in
your program is equivalent to 1 minute.
Sample output:
Code:
...
Buffer A: 11
Buffer C: 4
Worker X packing B: 3
Buffer B: 8
Worker Y packing C: 2
Buffer A: 12
Production line A suspended.
...

2. Relevant commands, code, scripts, algorithms:
the code i am provided ,try my best to do it le


3. The attempts at a solution (include all code and scripts):
Code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <semaphore.h>
void *A(void *arg);
void *B(void *arg);
void *C(void *arg);

int main()
{
    int res, total = 0;
    pthread_t b_thread, e_thread, s_thread;
    void *thread_result;
    res = sem_init(&A, B, C 0, 0);
    if (res != 0) {
	perror("Semaphore initialization failed");
	exit(EXIT_FAILURE);
    }
//create the thread that prepares A
    res = pthread_create(&b_thread, A, NULL);
    if (res != 0) {
	perror("Thread creation failed");
	exit(EXIT_FAILURE);
    }
//create the thread that prepares B
    res = pthread_create(&s_thread, NULL, B, NULL);
    if (res != 0) {
	perror("Thread creation failed");
	exit(EXIT_FAILURE);
    }
//create the thread that prepares C
    res = pthread_create(&s_thread, NULL, C, NULL);
    if (res != 0) {
	perror("Thread creation failed");
	exit(EXIT_FAILURE);
    }
    and(getpid());
    while (total < 12) {
	sleep(rand() % 3 + 1);
	sem_post(&A);
	printf("A ready\n");
	total++;
    }
    printf("\nWaiting for thread to finish...\n");
    res = pthread_join(b_thread, &thread_result);
    if (res != 0) {
	perror("Thread join failed");
	exit(EXIT_FAILURE);
    }
    printf("Thread joined\n");
    res = pthread_join(s_thread, &thread_result);
    if (res != 0) {
	perror("Thread join failed");
	exit(EXIT_FAILURE);
    }
    printf("Thread joined\n");
    sem_destroy(&B);
    exit(EXIT_SUCCESS);
}
void *A(void *arg)
{
    int i;
    srand(time(NULL));
    for (i = 0; i < 7; i++) {
	sem_wait(&B);
	sleep(rand() % 4 + 1);
	printf("A prepared.\n");
    }
    pthread_exit(NULL);
}
void *B(void *arg)
{
    int i;
    srand(time(NULL));
    for (i = 0; i < 5; i++) {
	sem_wait(&A);
	sleep(rand() % 3 + 1);
	printf("B prepared.\n");
    }
    pthread_exit(NULL);
}
void *C(void *arg)
{
    int i;
    srand(time(NULL));
    for (i = 0; i < 5; i++) {
	sem_wait(&A);
	sleep(rand() % 3 + 1);
	printf("C prepared.\n");
    }
    pthread_exit(NULL);
}


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

jennifer
utar kampar ,perak,malasysia
computer enginnering


Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by pludi; 04-11-2010 at 07:46 AM.. Reason: fixed fonts and indentation
# 2  
Old 04-11-2010
School, course and professor/instructor information not correct.

Need complete information.

Thread closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Linux

Customized Linux Operating System with Security Authentication

Dear Gurus/Experts of UNIX/LINUX, Im Isravel from India, I've customized CentOS Installation ISO as per my new product requirements. I want to give serial key authentication to the clients who all are trying to install ISO file. Can anyone guide me how to create serial key authentication... (1 Reply)
Discussion started by: isravelraja
1 Replies

2. UNIX for Dummies Questions & Answers

How much take space Linux operating system?

Hi Guys, I have a PC (laptop), where ram is 1 GB, hard disk is 400 GB, Now in my PC has window7 & oracle 10g, suppose if we now installed linux then will my system work or we should remove window7 now, please let me know that which linux version is take less space in PC. (3 Replies)
Discussion started by: aaditya321
3 Replies

3. Linux

Linux Operating system concepts

hi guys, i got job recently in a company which provide a product for data backup and data recovery... as dis product is wrriten in c++ am workin in c++.. now am under training and i want to learn abt Operating System concepts and OS programming using c and c++. i know basic c and c++ programming... (3 Replies)
Discussion started by: senthil.march
3 Replies

4. UNIX for Advanced & Expert Users

Best Operating System

Hello All, I want to install Linux on my machine, so please tell me one thing which is the best to install- 1.)Red Hat 2.)Cent OS 3.)Red Hat 4.)Ubuntu 5.)Fedora except that if there is any please tell me. (1 Reply)
Discussion started by: parthmittal2007
1 Replies

5. Ubuntu

establishing connection with e-kermit running on LINUX from my operating system

we designed a primitive operating system for learning basics fundamentals and we created process switching, interrupt/polled IO for device drivers like UART and printers. We accomplish this by using our own tools called SPEDE (for downloading compiled elf image from host ubuntu system that have... (0 Replies)
Discussion started by: bicepjai
0 Replies

6. UNIX for Advanced & Expert Users

Linux is kernel and solaris is operating system

Hi I was reading some weblog on the internet and someone made an interesting statement. <quote> Linux is kernel and solaris is operating system </quote> Honestly I don't understand the difference between term kernel and operating system in above quote. Could you explain me more ? thx... (4 Replies)
Discussion started by: presul
4 Replies

7. Homework & Coursework Questions

Operating system LINUX

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a C program that accepts 3 parameters. Each parameter indicates the quantity of product to be produced.... (0 Replies)
Discussion started by: paradise
0 Replies

8. Shell Programming and Scripting

Operating system LINUX

Write a C program that accepts 3 parameters. Each parameter indicates the quantity of product to be produced. Each product will be produced in different production line. Ready products will be placed in a buffer area located at the end of each production line. Packaging workers will pack the... (1 Reply)
Discussion started by: paradise
1 Replies

9. News, Links, Events and Announcements

Bangkok Post Article: The story behind the Linux operating system

http://www.bangkokpost.com/020403_Database/02Apr2003_datacol59.html (0 Replies)
Discussion started by: Neo
0 Replies
Login or Register to Ask a Question