Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write the C code for the file time.c based on the following instructions.(links to downloadable xv6 and its pdf book are below for reference).

Please write the C code for the file time.c based on the following instructions.(links to downloadable xv6 and its pdf book are below for reference).

use the following commands to git clone the xv6 into your ubuntu VM for this question in a terminal if you don't have it:

sudo apt-get update sudo apt-get upgrade sudo apt-get install git zip build-essential sudo apt-get install gdb-multiarch qemu-system-misc sudo apt-get install gcc-riscv64-linux-gnu sudo apt-get install binutils-riscv64-linux-gnu git clone https://github.com/mit-pdos/xv6-riscv.git xv6 chmod 700 -R xv6

Complete the following steps.

Implement a simplified version of the UNIX time1 command (reporting ticks2 ) Note, to make it easier, this time call will provide a program execution time in ticks instead of real, user and sys times. See Example Submission section for an example.

Time System Call A system call is how a program requests service from an operating systems kernel. System calls may include hardware related services, creation and execution of new processes and process scheduling. It is also possible for a system call to be made only from user space processes.

Time Command In this assignment you will implement a system call to get the current time, and a simplified version of the UNIX time command. This command measures how long it takes for some other command to execute. For example, if we run time ls the time command will run ls, then when that's done tells us how long it took to execute. Usually this is measured in seconds, but for this project time is measured in ticks (100 ticks equals to one second of real time).

FILE: user/time.c

This file is the implementation of the simplified time command from bash. This is in user space and therefore is written in C. Implementing the program requires you to use the system call added in the earlier section and other xv6 system calls, in particular fork(), exec(), and wait(). You can find a detailed explanation of these in Chapter 1 Operating System Interfaces of the xv6 textbook.

ACTION: You are must create a new file called time.c and create a program that will:

Accepts arguments from the command line interface. You are expected to do the necessary error checking with appropriate error messages.

Fork a child process. The parent process is responsible for measuring the time it takes for the child to finish executing. A outline of the step involved is as follows: Get the current time using uptime. Use the fork() system call and then wait for the child process to terminate. When use the wait() system call returns to the parent process get the current time again and calculate the difference.

You should return an error message if the fork() is unsuccessful.

The child process is responsible for: Executing the command as per the user provided command line arguments via the exec() call. You must determine how you will pass the arguments from the command line. The child should return an error message if execution fails.

Hint: Code time.c after youve finished making the system call accessible in the kernel and editing the Makefile. This way you can test and debug as you program. This is in xv6 so the files that need to be edited for this to work are: xv6/Makefile, xv6/user/user.h, xv6/user/usys.pl, xv6/kernel/syscall.h, xv6/kernel/syscall.c, xv6/kernel/sysproc.c

Build xv6 as follows in terminal when done: make clean make qemu

Testing Time System Call Once you are done with your program, you can test it and execute make qemu. Type in a simple time ls command and see if the system call is working as intended.

image text in transcribed

xv6 Reference Book: https://pdos.csail.mit.edu/6.828/2020/xv6/book-riscv-rev1.pdf 2.

$timelsREADMEcatechoforktestgrepinitkilllnlsmkdirrmshstressfsusertestsgrindwczombietimetracesysinfotestconsoleReal-timeinticks:$1122222222222222222222321123456789101112131415161718192021221024102420592400822832131842735223920228082275226232229042288841760239041535683806425144222962516023192273360

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions