
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
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):
Code a C++
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
$ ps -A | grep kworker | wc -l
$ ./processes sshd
$ ps -A | grep sshd | wc -l
$ ./processes scsi
$ ps -A | grep scsi | wc -l
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 5 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
- Write two c++ programs to implement a distributed version of a multithreaded Huffman decompressor using the one in project 1 The server program The user will execute this program using the following syntax: ./exec_filename port_no < input_filename where exec_filename is the name of your executable file, port_no is the port number to create the socket, and input_filename is the name of the file with the alphabet's information. The port number will be available to the server program as a command-line argument. The server program receives from STDIN the alphabet's information (using input redirection). The input file has multiple lines, where each line contains information (character and frequency) about a symbol from the alphabet. The input file format is as follows: A char representing the symbol. An integer representing the frequency of the symbol. Example Input File: E 3 G 3 F 1 H 2 Given the previous input file, the expected output for the server program is: Symbol: G,…arrow_forwardSemaphores: Select all of the following statements that are true. The operations P (Test) and V (Signal) can be interrupted. The operations P (Test) and V (Signal) run in the operating system's user mode. The values of binary semaphores are restricted to 0 and 1. Counting semaphores are used to manage limited resources and the corresponding access to them. Semaphores can be used to synchronize certain operations between processes. When accessing the list of a semaphore, the FIFO principle should be preferred to the LIFO principle.arrow_forwardWrite two c++ programs to implement a distributed version of a multithreaded Huffman decompressor using the one in project 1 The server program The user will execute this program using the following syntax: ./exec_filename port_no < input_filename where exec_filename is the name of your executable file, port_no is the port number to create the socket, and input_filename is the name of the file with the alphabet's information. The port number will be available to the server program as a command-line argument. The server program receives from STDIN the alphabet's information (using input redirection). The input file has multiple lines, where each line contains information (character and frequency) about a symbol from the alphabet. The input file format is as follows: A char representing the symbol. An integer representing the frequency of the symbol. Example Input File: E 3 G 3 F 1 H 2 Given the previous input file, the expected output for the server program is: Symbol: C,…arrow_forward
- in c++ Define a new exception class named “BadValueException” that must inherit from the exception class. It will manage and capture the general invalid integer and double value. It must be able to describe the reason for the error and save away the erroneous value. In another words, when the caller catches the exception and receives this object, it must know what the reason for the exception is and the actual bad value that caused the exception.arrow_forwardPython script that uses the sys module to perform the following tasks:1. In a main method:a. Read and print the command-line arguments when the script is run.b. Print the Python path (the directories where Python is looking for modules toimport).c. Print the Python version.d. Print the platform name.2. The main() function must only run automatically if the module is being run directly, notwhen imported.arrow_forwardIn UNIX, how would you remove the directory test and all files and subdirectories (recursively) in it? The directory test is located in (is a subdirectory of) /home/myid/smith/projects. O rmdir /home/myid/smith/projects/test O rmdir -r /home/myid/smith/projects/test rm -r /home/myid/smith/projects/test O rm -r projects/testarrow_forward
- Implement a simple version of the linux grep command in C++. grep - Looks through a file, line by line, trying to find a user-specified search term in the line. If a line has the word within it, the line is printed out, otherwise it is not. Use the system calls open(), getline(), close(). Requirements (examples run from. terminal) Your program grep is always passed a search term and zero or more files to grep through (thus, more than one is possible). It should go through each line and see if the search term is in it; if so, the line should be printed, and if not, the line should be skipped. [terminal]$ ./grep ! main.cpp main2.cppcout << "Hello, World!";cout << "Programming is great fun!"; The matching is case sensitive. Thus, if searching for world, lines with World will not match. Lines can be arbitrarily long (that is, you may see many many characters before you encounter a newline character, \n). grep should work as expected even with very long lines. For this,…arrow_forwardWhat do these errors mean in C# and how to fix them?arrow_forward
arrow_back_ios
arrow_forward_ios
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