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 -l 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 *”. 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 -l". 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 Stdout Parent wait for a child no change no change Child wc -l redirected from a grand-child's stdout no change Grand-child grep argv[1] redirected from a great-grand-child's stdout redirected to a child's stdin Great-grand- child ps -A no change redirected to a grand-child's stdin 4. What to Turn In On Canvas Program 1 must include: 1. Softcopy: processes.cpp file 2. A sample of output when running your program vs. actual system calls (to be included in 3. Report):                 $ ./processes kworker $ ps -A | grep kworker | wc -l $ ./processes sshd $ ps -A | grep sshd | wc -l $ ./processes scsi $ ps -A | grep scsi | wc -l

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
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 -l
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 *”.
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 -l". 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 Stdout
Parent
wait for a
child no change no change
Child wc -l redirected from a grand-child's stdout no change
Grand-child grep argv[1]
redirected from a great-grand-child's
stdout redirected to a child's stdin
Great-grand-
child ps -A no change
redirected to a grand-child's
stdin
4. What to Turn In On Canvas
Program 1 must include:
1. Softcopy:
processes.cpp file
2. A sample of output when running your program vs. actual system calls (to be
included in 3. Report):
 
 
 
 
 
 
 
 
$ ./processes kworker
$ ps -A | grep kworker | wc -l
$ ./processes sshd
$ ps -A | grep sshd | wc -l
$ ./processes scsi
$ ps -A | grep scsi | wc -l
 
Expert Solution
steps

Step by step

Solved in 5 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