SlideShare a Scribd company logo
1 of 5
CS 4760 Operating Systems
Assignment 2 Due Date: October 5th, 2016
Concurrent UNIX Processes and shared memory
The goal of this homework is to become familiar with
concurrent processing in Unix/Linux using shared memory. You
will write a program that uses multiple processes to increment a
number in shared memory and write a message into
a file. The multiple processes compete to get exclusive access to
the file to write into, participating in possibly two
race conditions (on the variable in shared memory and the file
access). You will use the multiple process Peterson’s
synchronization algorithm for the critical section problem. The
master process should allocate an integer in shared
memory (sharedNum) and initialize it to zero. Then generate by
default 5 slave processes using a master process
and make them write into a file called test.out in the directory
where the processes are running from. The message
to be written into the file is:
File modified by process number xx at time hh:mm with
sharedNum = yy
where xx is the process number as specified in the master. The
value of xx is between 1 and the max number of
slaves (master process is taken to be process 0). This implies
that the child process will be run by the command
slave xx
If a process starts to execute code to enter the critical section, it
must print a message to that effect on stderr. It
will be a good idea to include the time when that happens. Also,
indicate the time on stderr when the process
actually enters and exits the critical section. Within the critical
section, wait for [0-2] seconds before you increment
the variable and write into the file, and then, wait for another
[0-2] seconds before leaving the critical section. Each
slave should only enter its critical region by default only 3
times before it terminates. This can be changed per
command line options discussed later.
The code for each slave should use the following template:
for ( i = 0; i < max_writes; i++ )
{
execute code to enter critical section;
/* Critical section */
sleep for random amount of time (between 0 and 2 seconds);
increment sharedNum
write message into the file
sleep for random amount of time (between 0 and 2 seconds);
exit from critical section;
}
Your main executable should use command line arguments. You
must implement at least the following command
line arguments using getopt:
-h
-s x
-l filename
-i y
-t z
where x is the maximum number of slave processes spawned
(default 5) and filename is the log file used. The parameter
y determines how many times each slave should increment and
write to the file before terminating (default of 3).
The parameter z is the time in seconds when the master will
terminate itself (default 20)
Concurrent Unix Processes and shared memory 2
You will be required to create 5 separate slave processes from
your master. That is, master will just spawn the
5 slaves and wait for them to finish. It will also set up the
signal handler. It also sets a timer at the start of
computation to 20 seconds (make it configurable). If
computation has not finished by this time, master kills all the
spawned processes and then exits. Make sure that you print
appropriate message(s) from both master and each
slave.
In addition, master should print a message when an interrupt
signal (^C) is received. Make sure that all the
children/grandchildren are killed by master when this happens,
and all the shared memory is deallocated. The
slaves kill themselves upon receiving interrupt signal but print a
message on stderr to indicate that they are dying
because of an interrupt, along with the identification
information. Make sure that the processes handle multiple
interrupts correctly. As a precaution, add this feature only after
your program is well debugged.
Implementation
The code for master and slave processes should be compiled
separately and the executables be called master and
slave. The program should be executed by
./master
Other points to remember: You are required to use fork, execl
(or one of its variants), wait, and exit to manage
multiple processes. Use shmctl suite of calls for shared memory
allocation. Also make sure that you do not have
more than twenty processes in the system at any time. You can
do this by keeping a counter in master that gets
incremented by fork and decremented by wait.
Hints
You will need to set up shared memory in this project to allow
the processes to communicate with each other. Please
check the man pages for shmget, shmctl, shmat, and shmdt to
work with shared memory.
You will also need to set up signal processing and to do that,
you will check on the functions for signal and abort.
If you abort a process, make sure that the parent cleans up any
allocated shared memory before dying.
In case you face problems, please use the shell command ipcs to
find out any shared memory allocated to you and
free it by using ipcrm.
I HIGHLY SUGGEST YOU DO THIS PROJECT
INCREMENTALLY. Test out the command line options, then
spawn the slave processes but just have them all terminate.
Then encode the signal handling and termination after
a specified time. Then do shared memory and ensure all
processes have access to it. Be very weary of trying to do
multiple things at the same time.
What to handin
Handin an electronic copy of all the sources, README,
Makefile(s), and results using Mygateway.
Omission of a Makefile will result in a loss of 10 points, while
README will cost you 5 points. Make sure that there
is no shared memory left after your process finishes (normal or
interrupted termination).

More Related Content

Similar to CS 4760 Operating SystemsAssignment 2 Due Date October 5th,.docx

Similar to CS 4760 Operating SystemsAssignment 2 Due Date October 5th,.docx (20)

yyyyxxxdd
yyyyxxxddyyyyxxxdd
yyyyxxxdd
 
new title
new titlenew title
new title
 
yyyyxxx
yyyyxxxyyyyxxx
yyyyxxx
 
Tinoub1
Tinoub1Tinoub1
Tinoub1
 
yyyyxxxdd
yyyyxxxddyyyyxxxdd
yyyyxxxdd
 
Tinoub1
Tinoub1Tinoub1
Tinoub1
 
Toby5
Toby5Toby5
Toby5
 
Monit a2
Monit a2Monit a2
Monit a2
 
yyyyxxx
yyyyxxxyyyyxxx
yyyyxxx
 
Toby7
Toby7Toby7
Toby7
 
Tinoub1
Tinoub1Tinoub1
Tinoub1
 
Toby10
Toby10Toby10
Toby10
 
Toby7
Toby7Toby7
Toby7
 
Toby
Toby Toby
Toby
 
yyyyxxx
yyyyxxxyyyyxxx
yyyyxxx
 
toby
tobytoby
toby
 
Tinoub1
Tinoub1Tinoub1
Tinoub1
 
yyyyxxx
yyyyxxxyyyyxxx
yyyyxxx
 
Toby5
Toby5Toby5
Toby5
 
Tinou uniq 1
Tinou uniq 1Tinou uniq 1
Tinou uniq 1
 

More from annettsparrow

Initial Post  (250 words)Read and interpret the short story .docx
Initial Post  (250 words)Read and interpret the short story .docxInitial Post  (250 words)Read and interpret the short story .docx
Initial Post  (250 words)Read and interpret the short story .docxannettsparrow
 
initial post one paragraph intext citation and reference Require.docx
initial post one paragraph intext citation and reference Require.docxinitial post one paragraph intext citation and reference Require.docx
initial post one paragraph intext citation and reference Require.docxannettsparrow
 
Initial Post InstructionsTriggers are ethnocentric responses to .docx
Initial Post InstructionsTriggers are ethnocentric responses to .docxInitial Post InstructionsTriggers are ethnocentric responses to .docx
Initial Post InstructionsTriggers are ethnocentric responses to .docxannettsparrow
 
Initial Post InstructionsFor the initial post,consider thr.docx
Initial Post InstructionsFor the initial post,consider thr.docxInitial Post InstructionsFor the initial post,consider thr.docx
Initial Post InstructionsFor the initial post,consider thr.docxannettsparrow
 
Initial Post InstructionsFor the initial post, choose and ad.docx
Initial Post InstructionsFor the initial post, choose and ad.docxInitial Post InstructionsFor the initial post, choose and ad.docx
Initial Post InstructionsFor the initial post, choose and ad.docxannettsparrow
 
Initial Post InstructionsDiscuss the differences and similaritie.docx
Initial Post InstructionsDiscuss the differences and similaritie.docxInitial Post InstructionsDiscuss the differences and similaritie.docx
Initial Post InstructionsDiscuss the differences and similaritie.docxannettsparrow
 
Initial Post InstructionsAs we jump into the world of Alge.docx
Initial Post InstructionsAs we jump into the world of Alge.docxInitial Post InstructionsAs we jump into the world of Alge.docx
Initial Post InstructionsAs we jump into the world of Alge.docxannettsparrow
 
Initial Post InstructionsFor the initial post, respond to one .docx
Initial Post InstructionsFor the initial post, respond to one .docxInitial Post InstructionsFor the initial post, respond to one .docx
Initial Post InstructionsFor the initial post, respond to one .docxannettsparrow
 
Initial Post InstructionsAgenda setting can be a difficult t.docx
Initial Post InstructionsAgenda setting can be a difficult t.docxInitial Post InstructionsAgenda setting can be a difficult t.docx
Initial Post InstructionsAgenda setting can be a difficult t.docxannettsparrow
 
Initial Post Identify all the components of a cell. Describe the fu.docx
Initial Post Identify all the components of a cell. Describe the fu.docxInitial Post Identify all the components of a cell. Describe the fu.docx
Initial Post Identify all the components of a cell. Describe the fu.docxannettsparrow
 
Initial Discussion Board Post Compare and contrast life for col.docx
Initial Discussion Board Post Compare and contrast life for col.docxInitial Discussion Board Post Compare and contrast life for col.docx
Initial Discussion Board Post Compare and contrast life for col.docxannettsparrow
 
Infrastructure SecurityChapter 10Principles of Compute.docx
Infrastructure SecurityChapter 10Principles of Compute.docxInfrastructure SecurityChapter 10Principles of Compute.docx
Infrastructure SecurityChapter 10Principles of Compute.docxannettsparrow
 
Inital post please respond for the above post question one page with.docx
Inital post please respond for the above post question one page with.docxInital post please respond for the above post question one page with.docx
Inital post please respond for the above post question one page with.docxannettsparrow
 
Infornnation Technologyin Hunnan ResourceAnEmpirical .docx
Infornnation Technologyin Hunnan ResourceAnEmpirical .docxInfornnation Technologyin Hunnan ResourceAnEmpirical .docx
Infornnation Technologyin Hunnan ResourceAnEmpirical .docxannettsparrow
 
INFORMED CONSENT LETTER Page 1 of 2 SELF CONSENT .docx
INFORMED CONSENT LETTER  Page 1 of 2 SELF CONSENT .docxINFORMED CONSENT LETTER  Page 1 of 2 SELF CONSENT .docx
INFORMED CONSENT LETTER Page 1 of 2 SELF CONSENT .docxannettsparrow
 
INFORMATIONGOVERNANCEFounded in 1807, John W.docx
INFORMATIONGOVERNANCEFounded in 1807, John W.docxINFORMATIONGOVERNANCEFounded in 1807, John W.docx
INFORMATIONGOVERNANCEFounded in 1807, John W.docxannettsparrow
 
Informative Presentation Delivery OutlineI. HeaderSpeec.docx
Informative Presentation Delivery OutlineI.  HeaderSpeec.docxInformative Presentation Delivery OutlineI.  HeaderSpeec.docx
Informative Presentation Delivery OutlineI. HeaderSpeec.docxannettsparrow
 
Informed Consent FormBy the due date assigned, submit the Inform.docx
Informed Consent FormBy the due date assigned, submit the Inform.docxInformed Consent FormBy the due date assigned, submit the Inform.docx
Informed Consent FormBy the due date assigned, submit the Inform.docxannettsparrow
 
INFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docx
INFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docxINFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docx
INFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docxannettsparrow
 
Information Technology Capstone ProjectIn this course, learners .docx
Information Technology Capstone ProjectIn this course, learners .docxInformation Technology Capstone ProjectIn this course, learners .docx
Information Technology Capstone ProjectIn this course, learners .docxannettsparrow
 

More from annettsparrow (20)

Initial Post  (250 words)Read and interpret the short story .docx
Initial Post  (250 words)Read and interpret the short story .docxInitial Post  (250 words)Read and interpret the short story .docx
Initial Post  (250 words)Read and interpret the short story .docx
 
initial post one paragraph intext citation and reference Require.docx
initial post one paragraph intext citation and reference Require.docxinitial post one paragraph intext citation and reference Require.docx
initial post one paragraph intext citation and reference Require.docx
 
Initial Post InstructionsTriggers are ethnocentric responses to .docx
Initial Post InstructionsTriggers are ethnocentric responses to .docxInitial Post InstructionsTriggers are ethnocentric responses to .docx
Initial Post InstructionsTriggers are ethnocentric responses to .docx
 
Initial Post InstructionsFor the initial post,consider thr.docx
Initial Post InstructionsFor the initial post,consider thr.docxInitial Post InstructionsFor the initial post,consider thr.docx
Initial Post InstructionsFor the initial post,consider thr.docx
 
Initial Post InstructionsFor the initial post, choose and ad.docx
Initial Post InstructionsFor the initial post, choose and ad.docxInitial Post InstructionsFor the initial post, choose and ad.docx
Initial Post InstructionsFor the initial post, choose and ad.docx
 
Initial Post InstructionsDiscuss the differences and similaritie.docx
Initial Post InstructionsDiscuss the differences and similaritie.docxInitial Post InstructionsDiscuss the differences and similaritie.docx
Initial Post InstructionsDiscuss the differences and similaritie.docx
 
Initial Post InstructionsAs we jump into the world of Alge.docx
Initial Post InstructionsAs we jump into the world of Alge.docxInitial Post InstructionsAs we jump into the world of Alge.docx
Initial Post InstructionsAs we jump into the world of Alge.docx
 
Initial Post InstructionsFor the initial post, respond to one .docx
Initial Post InstructionsFor the initial post, respond to one .docxInitial Post InstructionsFor the initial post, respond to one .docx
Initial Post InstructionsFor the initial post, respond to one .docx
 
Initial Post InstructionsAgenda setting can be a difficult t.docx
Initial Post InstructionsAgenda setting can be a difficult t.docxInitial Post InstructionsAgenda setting can be a difficult t.docx
Initial Post InstructionsAgenda setting can be a difficult t.docx
 
Initial Post Identify all the components of a cell. Describe the fu.docx
Initial Post Identify all the components of a cell. Describe the fu.docxInitial Post Identify all the components of a cell. Describe the fu.docx
Initial Post Identify all the components of a cell. Describe the fu.docx
 
Initial Discussion Board Post Compare and contrast life for col.docx
Initial Discussion Board Post Compare and contrast life for col.docxInitial Discussion Board Post Compare and contrast life for col.docx
Initial Discussion Board Post Compare and contrast life for col.docx
 
Infrastructure SecurityChapter 10Principles of Compute.docx
Infrastructure SecurityChapter 10Principles of Compute.docxInfrastructure SecurityChapter 10Principles of Compute.docx
Infrastructure SecurityChapter 10Principles of Compute.docx
 
Inital post please respond for the above post question one page with.docx
Inital post please respond for the above post question one page with.docxInital post please respond for the above post question one page with.docx
Inital post please respond for the above post question one page with.docx
 
Infornnation Technologyin Hunnan ResourceAnEmpirical .docx
Infornnation Technologyin Hunnan ResourceAnEmpirical .docxInfornnation Technologyin Hunnan ResourceAnEmpirical .docx
Infornnation Technologyin Hunnan ResourceAnEmpirical .docx
 
INFORMED CONSENT LETTER Page 1 of 2 SELF CONSENT .docx
INFORMED CONSENT LETTER  Page 1 of 2 SELF CONSENT .docxINFORMED CONSENT LETTER  Page 1 of 2 SELF CONSENT .docx
INFORMED CONSENT LETTER Page 1 of 2 SELF CONSENT .docx
 
INFORMATIONGOVERNANCEFounded in 1807, John W.docx
INFORMATIONGOVERNANCEFounded in 1807, John W.docxINFORMATIONGOVERNANCEFounded in 1807, John W.docx
INFORMATIONGOVERNANCEFounded in 1807, John W.docx
 
Informative Presentation Delivery OutlineI. HeaderSpeec.docx
Informative Presentation Delivery OutlineI.  HeaderSpeec.docxInformative Presentation Delivery OutlineI.  HeaderSpeec.docx
Informative Presentation Delivery OutlineI. HeaderSpeec.docx
 
Informed Consent FormBy the due date assigned, submit the Inform.docx
Informed Consent FormBy the due date assigned, submit the Inform.docxInformed Consent FormBy the due date assigned, submit the Inform.docx
Informed Consent FormBy the due date assigned, submit the Inform.docx
 
INFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docx
INFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docxINFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docx
INFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docx
 
Information Technology Capstone ProjectIn this course, learners .docx
Information Technology Capstone ProjectIn this course, learners .docxInformation Technology Capstone ProjectIn this course, learners .docx
Information Technology Capstone ProjectIn this course, learners .docx
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

CS 4760 Operating SystemsAssignment 2 Due Date October 5th,.docx

  • 1. CS 4760 Operating Systems Assignment 2 Due Date: October 5th, 2016 Concurrent UNIX Processes and shared memory The goal of this homework is to become familiar with concurrent processing in Unix/Linux using shared memory. You will write a program that uses multiple processes to increment a number in shared memory and write a message into a file. The multiple processes compete to get exclusive access to the file to write into, participating in possibly two race conditions (on the variable in shared memory and the file access). You will use the multiple process Peterson’s synchronization algorithm for the critical section problem. The master process should allocate an integer in shared memory (sharedNum) and initialize it to zero. Then generate by default 5 slave processes using a master process and make them write into a file called test.out in the directory where the processes are running from. The message to be written into the file is: File modified by process number xx at time hh:mm with sharedNum = yy where xx is the process number as specified in the master. The value of xx is between 1 and the max number of slaves (master process is taken to be process 0). This implies that the child process will be run by the command slave xx If a process starts to execute code to enter the critical section, it
  • 2. must print a message to that effect on stderr. It will be a good idea to include the time when that happens. Also, indicate the time on stderr when the process actually enters and exits the critical section. Within the critical section, wait for [0-2] seconds before you increment the variable and write into the file, and then, wait for another [0-2] seconds before leaving the critical section. Each slave should only enter its critical region by default only 3 times before it terminates. This can be changed per command line options discussed later. The code for each slave should use the following template: for ( i = 0; i < max_writes; i++ ) { execute code to enter critical section; /* Critical section */ sleep for random amount of time (between 0 and 2 seconds); increment sharedNum write message into the file sleep for random amount of time (between 0 and 2 seconds); exit from critical section; } Your main executable should use command line arguments. You must implement at least the following command line arguments using getopt:
  • 3. -h -s x -l filename -i y -t z where x is the maximum number of slave processes spawned (default 5) and filename is the log file used. The parameter y determines how many times each slave should increment and write to the file before terminating (default of 3). The parameter z is the time in seconds when the master will terminate itself (default 20) Concurrent Unix Processes and shared memory 2 You will be required to create 5 separate slave processes from your master. That is, master will just spawn the 5 slaves and wait for them to finish. It will also set up the signal handler. It also sets a timer at the start of computation to 20 seconds (make it configurable). If computation has not finished by this time, master kills all the spawned processes and then exits. Make sure that you print appropriate message(s) from both master and each slave. In addition, master should print a message when an interrupt signal (^C) is received. Make sure that all the children/grandchildren are killed by master when this happens, and all the shared memory is deallocated. The
  • 4. slaves kill themselves upon receiving interrupt signal but print a message on stderr to indicate that they are dying because of an interrupt, along with the identification information. Make sure that the processes handle multiple interrupts correctly. As a precaution, add this feature only after your program is well debugged. Implementation The code for master and slave processes should be compiled separately and the executables be called master and slave. The program should be executed by ./master Other points to remember: You are required to use fork, execl (or one of its variants), wait, and exit to manage multiple processes. Use shmctl suite of calls for shared memory allocation. Also make sure that you do not have more than twenty processes in the system at any time. You can do this by keeping a counter in master that gets incremented by fork and decremented by wait. Hints You will need to set up shared memory in this project to allow the processes to communicate with each other. Please check the man pages for shmget, shmctl, shmat, and shmdt to work with shared memory. You will also need to set up signal processing and to do that, you will check on the functions for signal and abort. If you abort a process, make sure that the parent cleans up any allocated shared memory before dying. In case you face problems, please use the shell command ipcs to
  • 5. find out any shared memory allocated to you and free it by using ipcrm. I HIGHLY SUGGEST YOU DO THIS PROJECT INCREMENTALLY. Test out the command line options, then spawn the slave processes but just have them all terminate. Then encode the signal handling and termination after a specified time. Then do shared memory and ensure all processes have access to it. Be very weary of trying to do multiple things at the same time. What to handin Handin an electronic copy of all the sources, README, Makefile(s), and results using Mygateway. Omission of a Makefile will result in a loss of 10 points, while README will cost you 5 points. Make sure that there is no shared memory left after your process finishes (normal or interrupted termination).