Computers and Technology
Computers and Technology, 03.03.2020 05:00, briyuna15

Write a C program called time. c that determines the amount of time necessary to run a command from the command line. This program will be run as "./time " and will report the amount of elapsed time to run the specified command. This will involve using fork() and exec() functions, as well as the gettimeofday() function to determine the elapsed time. It will also require the use of two different IPC mechanisms.
The general strategy is to fork a child process that will execute the specified command. However, before the child executes the command, it will record a timestamp of the current time (which we term "starting time"). The parent process will wait for the child process to terminate. Once the child terminates, the parent will record the current timestamp for the ending time. The difference between the starting and ending times represents the elapsed time to execute the command. The example output below reports the amount of time to run the command ls:

./time ls
time. c
Time
Elapsed time: 0.25422

As the parent and child are separate processes, they will need to arrange how the starting time will be shared between them. You will write two versions of this program, each representing a different method of IPC.
The first version will have the child process write the starting time to a region of shared memory before it calls exec(). After the child process terminates, the parent will read the starting time from shared memory. Refer to Section 3.7.1 for details using POSIX shared memory. In that section, there are separate programs for the producer and consumer. As the solution to this problem requires only a single program, the region of shared memory can be established before the child process is forked, allowing both the parent and child processes access to the region of shared memory.
Hints:
you will use the shared memory to store the timestamps.
Using fork() to create a child process and record the starting time into the shared memory. Using exec() function to execute a command.
In the parent process, wait() until the child process terminates; record the ending time and compute the elapsed time.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 12:20, jshhs
When guido van rossum created python, he wanted to make a language that was more than other programming languages. a. code-based b. human-readable c. complex d. functional
Answers: 1
image
Computers and Technology, 24.06.2019 09:00, lisacarter0804
Why might you chose to crest a function resume
Answers: 1
image
Computers and Technology, 25.06.2019 09:20, autumnhuls5720
The adbusters' image of the gap logo on the silhouette of a head most likely relays the message that: a. the man in the ad needs a hat from the gap b. consumers should be suspicious of gap ads c. gap clothes make you look intelligent d. everyone should have the gap on their minds
Answers: 1
image
Computers and Technology, 25.06.2019 10:50, kkruvc
Which of the following is true of heuristics? a)heuristics always lead to correct solutions of a problem. b)heuristics represent commonly used approaches to the solution of a problem. c) heuristics are a slower way to solve problems than are other strategies. d)heuristics are used by computers but not by humans as problem-solving tools.
Answers: 3
Do you know the correct answer?
Write a C program called time. c that determines the amount of time necessary to run a command from...

Questions in other subjects:

Konu
Arts, 03.11.2020 23:40
Konu
History, 03.11.2020 23:40