Create a file, shared.txt

Assignment Help C/C++ Programming
Reference no: EM13161164

1. When your program starts, it shall do the following:
1. Create a file, SHARED.txt, in the current directory (cwd).
2. Write it's pid (Process ID) followed by a Carriage Return and Newline in the file.
3. Close the file SHARED.txt
4. Create a semaphore named SEM which the threads will use to manage access to the file
SHARED.txt.
5. Create 6 threads. Use the POSIX version of threads (i.e., pthread_create())
6. Block/wait for all six threads to complete their work.
7. Destroy the semaphore, then exit gracefully, printing a friendly message to the console
2. Each thread shall perform the following (note, each thread is running concurrently):
1. Periodically (even numbered threads - once every two seconds, odd numbered threads - once
every 3 seconds) get the semaphore SEM; once the thread has SEM, it will proceed to do the
following:
1. Open the file SHARED.txt and write the tid (thread id) of that thread (followed by a
Carriage Return and Newline)
2. Write to the console (print to stdout) "Thread <thread id> is running" followed by a
newline
3. Close the file SHARED.txt
4. Release the semaphore SEM
2. Repeat 9 more times (each thread writes to the file and console a total of 10 times)
3. exit
You will need to use the following POSIX system calls for creating and managing the semaphores with:
sem_init(), sem_wait(), sem_post(), and sem_destroy().

Reference no: EM13161164

Questions Cloud

Method named isallvowels that returns : Write a method named isAllVowels that returns whether a String consists entirely of vowels (a, e, i, o, or u, case-insensitively). If every character of the String is a vowel, your method should return true. If any character of the String is a non-vo..
Multidimensional arrays : multidimensional arrays to life, let's consider a specific example: How can you visualize a 4-dimensional array? How can you give meaning to each dimension this array has? What kind of application would such an array be useful for?
What is the energy required to move a mole of urea out : What is the energy required to move a mole of urea out of the kidney cells and into the urine?
What is the minimal total weight of cylinders : A scuba diver uses a special equipment for diving. He has a cylinder with two containers: one with oxygen and the other with nitrogen. Depending on the time he wants to stay under water and the depth of diving the scuba diver needs various amount of ..
Create a file, shared.txt : When your program starts, it shall do the following:1. Create a file, SHARED.txt, in the current directory (cwd). 2. Write it's pid (Process ID) followed by a Carriage Return and Newline in the file.
State divers breathing compressed air : The solubility of N2 in blood can be a serious problem (the "bends") for divers breathing compressed air (78% N2 by volume) at depths greater than 50 ft.
Hasanodddigit that returns whether any digit : d named hasAnOddDigit that returns whether any digit of a positive integer is odd. Your method should return true if the number has at least one odd digit and false if none of its digits are odd. 0, 2, 4, 6, and 8 are even digits, and 1, 3, 5, 7, 9 a..
Determine the microcanonical partition function : Determine the microcanonical partition function, omega. Determine fundamental relation of system, using Stirling's approximation Determine the energy and heat capacity for the system as a function of temperature using Stirling's approximation. Det..
Explain what is the partial pressure of nocl : what is the partial pressure of NOCl which reacted in order for the partial pressure of NO to be .084 atm? what is the partial pressure of Cl_2 at equilibrium what is the magnitude of K_p for the equation above?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd