
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Topic Video
Question
C++ please
![Statement of Work
Linux System Programming
Code a C++ program, named processes.cpp that receives one argument, (i.e., argv[1]) upon its
invocation and searches how many processes whose name is given in argv[1] are running on
the system where your program has been invoked. To be specific, your program should
demonstrate the same behavior as:
$ ps -A | grep argv[1] | wc -1
Implement processes using the following system calls:
1. pid_t fork(void ); creates a child process that differs from the parent process only in
terms of their process IDs.
2.
int execlp(const char *file, const char *arg, ..., (char *)0 ); replaces the current
process image with a new process image that will be loaded from file. The first
argument arg must be the same as file. The last argument is a NULL pointer of type
"char *".
Parent
Child
3. int pipe(int filedes [2] ); creates a pair of file descriptors (which point to a pipe
structure), and places them in the array pointed to by filedes. filedes[0] is for reading
data from the pipe, filedes[1] is for writing data to the pipe.
4.
int dup2(int oldfd, int newfd); creates in newfd a copy of the file descriptor oldfd.
5. pid_t wait(int *status ); waits for process termination
6. int close(int fd ); closes a file descriptor.
For more details, type the man command from the shell prompt line. Use only the system calls
listed above. Do not use the system system call. Imitate how the shell performs "ps -A | grep
argv[1] | wc-I". In other words, your parent process spawns a child that spawns a grand-child
that spawns a great-grand-child. Each process should execute a different command as follows:
Process
Stdin
Grand-child
Great-grand-
child
Command
wait for a
child
wc -1
grep argv[1]
ps -A
no change
redirected from a grand-child's stdout
redirected from a great-grand-child's
stdout
no change
no change
no change
Stdout
redirected to a child's stdin
redirected to a grand-child's
stdin](https://content.bartleby.com/qna-images/question/62e5c874-e834-42f1-938e-65f064ab1dfd/2da7b13d-8751-4bb2-933a-f3ec80a008ac/qta39h_thumbnail.png)
Transcribed Image Text:Statement of Work
Linux System Programming
Code a C++ program, named processes.cpp that receives one argument, (i.e., argv[1]) upon its
invocation and searches how many processes whose name is given in argv[1] are running on
the system where your program has been invoked. To be specific, your program should
demonstrate the same behavior as:
$ ps -A | grep argv[1] | wc -1
Implement processes using the following system calls:
1. pid_t fork(void ); creates a child process that differs from the parent process only in
terms of their process IDs.
2.
int execlp(const char *file, const char *arg, ..., (char *)0 ); replaces the current
process image with a new process image that will be loaded from file. The first
argument arg must be the same as file. The last argument is a NULL pointer of type
"char *".
Parent
Child
3. int pipe(int filedes [2] ); creates a pair of file descriptors (which point to a pipe
structure), and places them in the array pointed to by filedes. filedes[0] is for reading
data from the pipe, filedes[1] is for writing data to the pipe.
4.
int dup2(int oldfd, int newfd); creates in newfd a copy of the file descriptor oldfd.
5. pid_t wait(int *status ); waits for process termination
6. int close(int fd ); closes a file descriptor.
For more details, type the man command from the shell prompt line. Use only the system calls
listed above. Do not use the system system call. Imitate how the shell performs "ps -A | grep
argv[1] | wc-I". In other words, your parent process spawns a child that spawns a grand-child
that spawns a great-grand-child. Each process should execute a different command as follows:
Process
Stdin
Grand-child
Great-grand-
child
Command
wait for a
child
wc -1
grep argv[1]
ps -A
no change
redirected from a grand-child's stdout
redirected from a great-grand-child's
stdout
no change
no change
no change
Stdout
redirected to a child's stdin
redirected to a grand-child's
stdin
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 4 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- C++ please.arrow_forwardc++ How do you compare the scores of four departments: accounting, customer service, sales and marketing and list them from largest score to lowest. For example please enter the score for marketing cin>>marketing Please enter the score for accounting cin>>accounting (the same for customer service and sales) These are examples of how I am supposed have them places. Thank you.arrow_forward
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education