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. Parent Child 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 *" 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-1". 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 Command Stdin Grand-child Great-grand- child 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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
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
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Instruction Format
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
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education