Question: Time system call help xv6. 1. If command is time l , it should display in number of ticks 2. If command is time -s,

Time system call help xv6.

1. If command is time l, it should display in number of ticks 2. If command is time -s, it should display time in seconds (floating point value).

The code below can time the number inticks, im just struggling to do the check for the "-s" part if the user chooses to input that.

time.c

#include "types.h" #include "user.h" #include "date.h"

int main (int argc, char *argv[]) { int startTicks = uptime();

int pid = fork(); if (pid < 0) { printf(2, "Error: Invalid PID! "); exit(); } if (pid > 0) wait(); if (pid == 0) { if (exec(argv[1], argv + 1) < 0) { printf(2, "Error: Exec fails! "); exit(); } }

int endTicks = uptime();

int seconds = (endTicks - startTicks); printf(1, " Real Time in ticks: %d tick(s) ", seconds); exit(); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!