SlideShare a Scribd company logo
1 of 3
Download to read offline
a. Modify the C program ex.9 so that it simulates the Unix pipe command:
ls | grep .c | tail -4
b.. Implement following programs to exhibit UNIX Process Control:
A program where parent process sorts array elements in descending order and prints them out
and child process sorts array elements in ascending order and prints them out.
A program where parent process counts number of vowels in the given sentence and child
process will count number of words in the same sentence. The above programs should use
system calls like fork, exec and wait.
ex.9:
/*
simulates unix pipe
ls | grep .c
*/
#include
#include
#include
#define RD 0
#define WT 1
int main()
{
int fd[2];
pipe(fd);
switch(fork()) { // parent forks
case -1:
perror("Fork error");
break;
case 0: // child does the ls
close(fileno(stdout)); // no need for stdout here
dup(fd[WT]); // duplicate the descriptor for writing
close(fd[WT]);
close(fd[RD]);
execlp("ls", "ls", NULL);
break;
default: // parent does the grep
close(fileno(stdin)); // no need for stdin here
dup(fd[RD]); // duplicate the descriptor for reading
close(fd[WT]);
close(fd[RD]);
execlp("grep", "grep", ".c", NULL);
break;
}
return 0;
}
Solution
#include
#include
#include
#define RD 0
#define WT 1
int main()
{
int fd1[2];
int fd2[2];
pipe(fd1);
switch(fork()) {
case -1:
perror("Fork error");
break;
case 0: // child does the ls
close(fileno(stdout));
dup(fd[WT]);
close(fd1[WT]);
close(fd1[RD]);
execlp("ls", "ls", NULL);
break;
default:
pipe(fd2);
switch(fork()) {
case -1:
perror("Fork error");
break;
case 0:
close(fileno(stdin));
dup(fd1[RD]);
dup(fd2[RD];
close(fd1[WT]);
close(fd1[RD]);
close(fd2[WT]);
close(fd2[RD]);
execlp("grep", "grep", ".c", NULL);
break;
default:
dup(fd2[RD]);
close(fd2[WT]);
close(fd2[RD]);
execlp("tail", "tail", "-4", NULL);
break;
}
return 0;
}

More Related Content

Similar to a. Modify the C program ex.9 so that it simulates the Unix pipe comm.pdf

1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docxtarifarmarie
 
Unit_V_Files handling in c programming language.pptx
Unit_V_Files handling in c programming language.pptxUnit_V_Files handling in c programming language.pptx
Unit_V_Files handling in c programming language.pptxraushankumarthakur7
 
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptxChapter 1_C Fundamentals_HS_Tech Yourself C.pptx
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptxssuser71a90c
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language CourseVivek chan
 
complete data structure
complete data structurecomplete data structure
complete data structureAnuj Arora
 
Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01Getachew Ganfur
 
Mychurch File Upload
Mychurch File UploadMychurch File Upload
Mychurch File UploadJoe Suh
 
Unix And C
Unix And CUnix And C
Unix And CDr.Ravi
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manualSami Said
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiSowmya Jyothi
 

Similar to a. Modify the C program ex.9 so that it simulates the Unix pipe comm.pdf (20)

C structure
C structureC structure
C structure
 
Ch02.pdf
Ch02.pdfCh02.pdf
Ch02.pdf
 
1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx
 
Unit_V_Files handling in c programming language.pptx
Unit_V_Files handling in c programming language.pptxUnit_V_Files handling in c programming language.pptx
Unit_V_Files handling in c programming language.pptx
 
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptxChapter 1_C Fundamentals_HS_Tech Yourself C.pptx
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
 
CC 3 - Module 2.pdf
CC 3 - Module 2.pdfCC 3 - Module 2.pdf
CC 3 - Module 2.pdf
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 
Os lab final
Os lab finalOs lab final
Os lab final
 
Unix t2
Unix t2Unix t2
Unix t2
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
Programming in c
Programming in cProgramming in c
Programming in c
 
complete data structure
complete data structurecomplete data structure
complete data structure
 
Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01
 
Mychurch File Upload
Mychurch File UploadMychurch File Upload
Mychurch File Upload
 
C tutorial
C tutorialC tutorial
C tutorial
 
Basic c
Basic cBasic c
Basic c
 
Presentation 2.ppt
Presentation 2.pptPresentation 2.ppt
Presentation 2.ppt
 
Unix And C
Unix And CUnix And C
Unix And C
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
 

More from ebrahimbadushata00

irktors (lcloding his accoueting instructor thmivenity c. All student.pdf
irktors (lcloding his accoueting instructor thmivenity c. All student.pdfirktors (lcloding his accoueting instructor thmivenity c. All student.pdf
irktors (lcloding his accoueting instructor thmivenity c. All student.pdfebrahimbadushata00
 
Is there a solution manual to group dynamics for team (fourth Editio.pdf
Is there a solution manual to group dynamics for team (fourth Editio.pdfIs there a solution manual to group dynamics for team (fourth Editio.pdf
Is there a solution manual to group dynamics for team (fourth Editio.pdfebrahimbadushata00
 
IntroductionFor this program, you will implement an interface that.pdf
IntroductionFor this program, you will implement an interface that.pdfIntroductionFor this program, you will implement an interface that.pdf
IntroductionFor this program, you will implement an interface that.pdfebrahimbadushata00
 
In Python,Create a program that asks the user for a number and the.pdf
In Python,Create a program that asks the user for a number and the.pdfIn Python,Create a program that asks the user for a number and the.pdf
In Python,Create a program that asks the user for a number and the.pdfebrahimbadushata00
 
In contrast to sexual reproduction in animals, sexually-reproducing .pdf
In contrast to sexual reproduction in animals, sexually-reproducing .pdfIn contrast to sexual reproduction in animals, sexually-reproducing .pdf
In contrast to sexual reproduction in animals, sexually-reproducing .pdfebrahimbadushata00
 
Ignore what I have written because Im pretty sure its wrong. Thank.pdf
Ignore what I have written because Im pretty sure its wrong. Thank.pdfIgnore what I have written because Im pretty sure its wrong. Thank.pdf
Ignore what I have written because Im pretty sure its wrong. Thank.pdfebrahimbadushata00
 
How can crisis leadership be learnedSolutionAn organization n.pdf
How can crisis leadership be learnedSolutionAn organization n.pdfHow can crisis leadership be learnedSolutionAn organization n.pdf
How can crisis leadership be learnedSolutionAn organization n.pdfebrahimbadushata00
 
Given the following information on a project develop early and la.pdf
Given the following information on a project develop early and la.pdfGiven the following information on a project develop early and la.pdf
Given the following information on a project develop early and la.pdfebrahimbadushata00
 
Global Economy, National Economies, and CompetitionIn the first pa.pdf
Global Economy, National Economies, and CompetitionIn the first pa.pdfGlobal Economy, National Economies, and CompetitionIn the first pa.pdf
Global Economy, National Economies, and CompetitionIn the first pa.pdfebrahimbadushata00
 
Explain why owners equity includes common stock as a liability eve.pdf
Explain why owners equity includes common stock as a liability eve.pdfExplain why owners equity includes common stock as a liability eve.pdf
Explain why owners equity includes common stock as a liability eve.pdfebrahimbadushata00
 
Evaluate the statements below and determine which is the best reason.pdf
Evaluate the statements below and determine which is the best reason.pdfEvaluate the statements below and determine which is the best reason.pdf
Evaluate the statements below and determine which is the best reason.pdfebrahimbadushata00
 
Discuss the Economic Benefits from Immigration.SolutionImmigra.pdf
Discuss the Economic Benefits from Immigration.SolutionImmigra.pdfDiscuss the Economic Benefits from Immigration.SolutionImmigra.pdf
Discuss the Economic Benefits from Immigration.SolutionImmigra.pdfebrahimbadushata00
 
Conclusion Phases of Oxidative Phosphorylation Focus your attention.pdf
Conclusion Phases of Oxidative Phosphorylation  Focus your attention.pdfConclusion Phases of Oxidative Phosphorylation  Focus your attention.pdf
Conclusion Phases of Oxidative Phosphorylation Focus your attention.pdfebrahimbadushata00
 
Computer Forensics Process Please respond to the followingThe.pdf
Computer Forensics Process Please respond to the followingThe.pdfComputer Forensics Process Please respond to the followingThe.pdf
Computer Forensics Process Please respond to the followingThe.pdfebrahimbadushata00
 
ArticleHinduism and Caste Systemby Jayaram VHinduism is a univ.pdf
ArticleHinduism and Caste Systemby Jayaram VHinduism is a univ.pdfArticleHinduism and Caste Systemby Jayaram VHinduism is a univ.pdf
ArticleHinduism and Caste Systemby Jayaram VHinduism is a univ.pdfebrahimbadushata00
 
Can someone solveexplain this I thought I was understanding this, .pdf
Can someone solveexplain this I thought I was understanding this, .pdfCan someone solveexplain this I thought I was understanding this, .pdf
Can someone solveexplain this I thought I was understanding this, .pdfebrahimbadushata00
 
C The ame compound componda with F Souls . E Difluut eoupou ds with.pdf
C The ame compound componda with F Souls . E  Difluut eoupou ds with.pdfC The ame compound componda with F Souls . E  Difluut eoupou ds with.pdf
C The ame compound componda with F Souls . E Difluut eoupou ds with.pdfebrahimbadushata00
 
Background Sometimes the standard C libraries (stdio.h, stdlib.h, e.pdf
Background Sometimes the standard C libraries (stdio.h, stdlib.h, e.pdfBackground Sometimes the standard C libraries (stdio.h, stdlib.h, e.pdf
Background Sometimes the standard C libraries (stdio.h, stdlib.h, e.pdfebrahimbadushata00
 
A severe B12 deficiency can cause megaloblastic anemia but in severe .pdf
A severe B12 deficiency can cause megaloblastic anemia but in severe .pdfA severe B12 deficiency can cause megaloblastic anemia but in severe .pdf
A severe B12 deficiency can cause megaloblastic anemia but in severe .pdfebrahimbadushata00
 
When you are admitted to the hospital for surgery, you are very ofte.pdf
When you are admitted to the hospital for surgery, you are very ofte.pdfWhen you are admitted to the hospital for surgery, you are very ofte.pdf
When you are admitted to the hospital for surgery, you are very ofte.pdfebrahimbadushata00
 

More from ebrahimbadushata00 (20)

irktors (lcloding his accoueting instructor thmivenity c. All student.pdf
irktors (lcloding his accoueting instructor thmivenity c. All student.pdfirktors (lcloding his accoueting instructor thmivenity c. All student.pdf
irktors (lcloding his accoueting instructor thmivenity c. All student.pdf
 
Is there a solution manual to group dynamics for team (fourth Editio.pdf
Is there a solution manual to group dynamics for team (fourth Editio.pdfIs there a solution manual to group dynamics for team (fourth Editio.pdf
Is there a solution manual to group dynamics for team (fourth Editio.pdf
 
IntroductionFor this program, you will implement an interface that.pdf
IntroductionFor this program, you will implement an interface that.pdfIntroductionFor this program, you will implement an interface that.pdf
IntroductionFor this program, you will implement an interface that.pdf
 
In Python,Create a program that asks the user for a number and the.pdf
In Python,Create a program that asks the user for a number and the.pdfIn Python,Create a program that asks the user for a number and the.pdf
In Python,Create a program that asks the user for a number and the.pdf
 
In contrast to sexual reproduction in animals, sexually-reproducing .pdf
In contrast to sexual reproduction in animals, sexually-reproducing .pdfIn contrast to sexual reproduction in animals, sexually-reproducing .pdf
In contrast to sexual reproduction in animals, sexually-reproducing .pdf
 
Ignore what I have written because Im pretty sure its wrong. Thank.pdf
Ignore what I have written because Im pretty sure its wrong. Thank.pdfIgnore what I have written because Im pretty sure its wrong. Thank.pdf
Ignore what I have written because Im pretty sure its wrong. Thank.pdf
 
How can crisis leadership be learnedSolutionAn organization n.pdf
How can crisis leadership be learnedSolutionAn organization n.pdfHow can crisis leadership be learnedSolutionAn organization n.pdf
How can crisis leadership be learnedSolutionAn organization n.pdf
 
Given the following information on a project develop early and la.pdf
Given the following information on a project develop early and la.pdfGiven the following information on a project develop early and la.pdf
Given the following information on a project develop early and la.pdf
 
Global Economy, National Economies, and CompetitionIn the first pa.pdf
Global Economy, National Economies, and CompetitionIn the first pa.pdfGlobal Economy, National Economies, and CompetitionIn the first pa.pdf
Global Economy, National Economies, and CompetitionIn the first pa.pdf
 
Explain why owners equity includes common stock as a liability eve.pdf
Explain why owners equity includes common stock as a liability eve.pdfExplain why owners equity includes common stock as a liability eve.pdf
Explain why owners equity includes common stock as a liability eve.pdf
 
Evaluate the statements below and determine which is the best reason.pdf
Evaluate the statements below and determine which is the best reason.pdfEvaluate the statements below and determine which is the best reason.pdf
Evaluate the statements below and determine which is the best reason.pdf
 
Discuss the Economic Benefits from Immigration.SolutionImmigra.pdf
Discuss the Economic Benefits from Immigration.SolutionImmigra.pdfDiscuss the Economic Benefits from Immigration.SolutionImmigra.pdf
Discuss the Economic Benefits from Immigration.SolutionImmigra.pdf
 
Conclusion Phases of Oxidative Phosphorylation Focus your attention.pdf
Conclusion Phases of Oxidative Phosphorylation  Focus your attention.pdfConclusion Phases of Oxidative Phosphorylation  Focus your attention.pdf
Conclusion Phases of Oxidative Phosphorylation Focus your attention.pdf
 
Computer Forensics Process Please respond to the followingThe.pdf
Computer Forensics Process Please respond to the followingThe.pdfComputer Forensics Process Please respond to the followingThe.pdf
Computer Forensics Process Please respond to the followingThe.pdf
 
ArticleHinduism and Caste Systemby Jayaram VHinduism is a univ.pdf
ArticleHinduism and Caste Systemby Jayaram VHinduism is a univ.pdfArticleHinduism and Caste Systemby Jayaram VHinduism is a univ.pdf
ArticleHinduism and Caste Systemby Jayaram VHinduism is a univ.pdf
 
Can someone solveexplain this I thought I was understanding this, .pdf
Can someone solveexplain this I thought I was understanding this, .pdfCan someone solveexplain this I thought I was understanding this, .pdf
Can someone solveexplain this I thought I was understanding this, .pdf
 
C The ame compound componda with F Souls . E Difluut eoupou ds with.pdf
C The ame compound componda with F Souls . E  Difluut eoupou ds with.pdfC The ame compound componda with F Souls . E  Difluut eoupou ds with.pdf
C The ame compound componda with F Souls . E Difluut eoupou ds with.pdf
 
Background Sometimes the standard C libraries (stdio.h, stdlib.h, e.pdf
Background Sometimes the standard C libraries (stdio.h, stdlib.h, e.pdfBackground Sometimes the standard C libraries (stdio.h, stdlib.h, e.pdf
Background Sometimes the standard C libraries (stdio.h, stdlib.h, e.pdf
 
A severe B12 deficiency can cause megaloblastic anemia but in severe .pdf
A severe B12 deficiency can cause megaloblastic anemia but in severe .pdfA severe B12 deficiency can cause megaloblastic anemia but in severe .pdf
A severe B12 deficiency can cause megaloblastic anemia but in severe .pdf
 
When you are admitted to the hospital for surgery, you are very ofte.pdf
When you are admitted to the hospital for surgery, you are very ofte.pdfWhen you are admitted to the hospital for surgery, you are very ofte.pdf
When you are admitted to the hospital for surgery, you are very ofte.pdf
 

Recently uploaded

When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 

Recently uploaded (20)

When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 

a. Modify the C program ex.9 so that it simulates the Unix pipe comm.pdf

  • 1. a. Modify the C program ex.9 so that it simulates the Unix pipe command: ls | grep .c | tail -4 b.. Implement following programs to exhibit UNIX Process Control: A program where parent process sorts array elements in descending order and prints them out and child process sorts array elements in ascending order and prints them out. A program where parent process counts number of vowels in the given sentence and child process will count number of words in the same sentence. The above programs should use system calls like fork, exec and wait. ex.9: /* simulates unix pipe ls | grep .c */ #include #include #include #define RD 0 #define WT 1 int main() { int fd[2]; pipe(fd); switch(fork()) { // parent forks case -1: perror("Fork error"); break; case 0: // child does the ls close(fileno(stdout)); // no need for stdout here dup(fd[WT]); // duplicate the descriptor for writing close(fd[WT]);
  • 2. close(fd[RD]); execlp("ls", "ls", NULL); break; default: // parent does the grep close(fileno(stdin)); // no need for stdin here dup(fd[RD]); // duplicate the descriptor for reading close(fd[WT]); close(fd[RD]); execlp("grep", "grep", ".c", NULL); break; } return 0; } Solution #include #include #include #define RD 0 #define WT 1 int main() { int fd1[2]; int fd2[2]; pipe(fd1); switch(fork()) { case -1: perror("Fork error"); break; case 0: // child does the ls close(fileno(stdout));
  • 3. dup(fd[WT]); close(fd1[WT]); close(fd1[RD]); execlp("ls", "ls", NULL); break; default: pipe(fd2); switch(fork()) { case -1: perror("Fork error"); break; case 0: close(fileno(stdin)); dup(fd1[RD]); dup(fd2[RD]; close(fd1[WT]); close(fd1[RD]); close(fd2[WT]); close(fd2[RD]); execlp("grep", "grep", ".c", NULL); break; default: dup(fd2[RD]); close(fd2[WT]); close(fd2[RD]); execlp("tail", "tail", "-4", NULL); break; } return 0; }