
Use a Linux machine and run the system calls, fork(), wait() and exec()
Write a
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main (int args, char *argv[])
{
pid_t fork_return;
pid_t pid;
pid=getpid();
fork_return = fork();
// When fork() returns -1, an error has happened.
printf("\nError creating process " );
return 0;
}
if (fork_return==0) {
// When fork() returns 0, we are in the child process.
printf("\n\nThe values are Child ID = %d, Parent ID=%d\n", getpid(), getppid());
execl("/bin/cat", "cat", "-b", "-v", "-t", argv[1], NULL);
}
else {
// When fork() returns a positive number, we are in the parent process
// and the return value is the PID of the newly created child process.
wait(NULL);
printf("\nChild Completes " );
printf("\nIn the Parent Process\n");
printf("Child Id = %d, Parent ID = %d\n", getpid(), getppid());
}
return 0;
}
Code for “testOS.c” to compile and run:
Details:
-
Type the following program in Linux
-
Compile it using gcc as gcc testOS.c
-
Run the program as the following command: ./a.out filename where filename is the name of a text file that you have created. The text file should contain multiple lines of text.
HiNT:
What should happen:
The code will fork(), The child will use the execl to call cat and use the filename passed as an argument on the command line. The parent will wait for the child to finish. Your program will print from both processes:
-
The process id
-
The parent id
to generate a solution
a solution
- I need help with my Python code please I am getting errors. def read_data(filename): try: with open(filename, "r") as file: return file.read() except Exception as exception: print(exception) return None def extract_data(tags, strings): data = [] start_tag = f"<{tags}>" end_tag = f"</{tags}>" while start_tag in strings: try: start_index = strings.find(start_tag) + len(start_tag) end_index = strings.find(end_tag) value = strings[start_index:end_index] if value: data.append(value) strings = strings[end_index + len(end_tag):] except Exception as exception: print(exception) return data def get_names(string): names = extract_data("name", string) return names def get_descriptions(string): descriptions = extract_data("description", string) return descriptions def get_calories(string): calories = extract_data("calories",…arrow_forwardCreate a simple java program that reads all the content in a .txt file, the user will enter the filename to be opened and once opened with any stream of choice, all the content in the file is printed to the screen. You are additionally expected to deal most common exceptions(See samples below) [HINT: DO NOT PROVIDE A PATH BUT RATHER ONLY OPEN THE FILE WITH RELATIVE PATH/FILENAME] Sample run 1: Enter filename: input.txt sample output 1: Hello files, I got the content NB: input.txt contains "Hello files, I got the content" as the data [See sample file]arrow_forwardQuestion 3 Which statement is true about exception handling? O The override specifier overrides the normal stack unwinding process. O Exception handling should be used sparingly, when other methods of error checking are available. O It moderately improves the speed performance of most programs. O Exceptions are ignored by any function labeled noexcept that throws an exception. O It is an example of RAII.arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





