Question: xv6 time.c system call and linkage create a new file called time.c, and create a program that will: Accepts arguments from the command line interface.
xv6 time.c system call and linkage
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 the corresponding error message. Fork a child process, the parent process is responsible to measure the time it takes for the child process to finish executing. o Get the current time using uptime. o Fork and then wait for the child process to terminate. o Then when wait returns in the parent process, get the current time again and calculate the difference.
Return an error message if fork is unsuccessful. The child process is responsible for executing the command the user wishes to time using the exec command. You must determine how you will pass the arguments from the command line. o The child is responsible to return an error message is execution fails.
help creating method and implementing the system call in sysproc.c
#include "types.h" #include "x86.h" #include "defs.h" #include "date.h" #include "param.h" #include "memlayout.h" #include "mmu.h" #include "proc.h"
int sys_fork(void) { return fork(); }
int sys_exit(void) { exit(); return 0; // not reached }
int sys_wait(void) { return wait(); }
int sys_kill(void) { int pid;
if(argint(0, &pid) < 0) return -1; return kill(pid); }
int sys_getpid(void) { return myproc()->pid; }
int sys_sbrk(void) { int addr; int n;
if(argint(0, &n) < 0) return -1; addr = myproc()->sz; if(growproc(n) < 0) return -1; return addr; }
int sys_sleep(void) { int n; uint ticks0;
if(argint(0, &n) < 0) return -1; acquire(&tickslock); ticks0 = ticks; while(ticks - ticks0 < n){ if(myproc()->killed){ release(&tickslock); return -1; } sleep(&ticks, &tickslock); } release(&tickslock); return 0; }
// return how many clock tick interrupts have occurred // since start. int sys_uptime(void) { uint xticks;
acquire(&tickslock); xticks = ticks; release(&tickslock); return xticks; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
