Question: This question requires you to modify the source code of xv 6 - riscv. Make sure you start with a fresh copy of the original

This question requires you to modify the source code of xv6-riscv. Make sure you start with a fresh copy of the original xv6 code.
There is a ps command on Linux and on MacOS. You are required to implement a simple version of the ps command for xv6. You should first become familiar with this command on Linux or MacOS. Documentation of this command can be displayed using the man ps command, while ps --help all will list all the options available in a shorter format.
Task 1: Implement a simple version of the ps command on xv6-riscv. When used without any command-line argument, this command should display information of all current processes in xv6 that are either running or sleeping. The information should include:
Process ID
Parent process ID
State
Name of process
Size (in bytes)
An example of the command and output is as follows:
$ ps 10 sleep init 1228821 sleep sh 1638442 running ps 12288 There are a total of 3 processes in the system
This information can be found in the process table in the kernel part of the xv6 code. It is an array of struct proc, one structure per process. You may only access it from code running in kernel mode. Hence you will need to implement a system call that displays this information for you. In addition, you will need to write the ps program as a user program.
Task 2: Modify your ps program to check for any command-line arguments. If the argument is -r then display only the information of the running process. If the user enter any other argument, an error message should be displayed instead. Since you have not learnt how to pass information through a system call yet, a simpler way is to set up another system call to display this.
An example output:
$ ps -r 42 running ps 12288
2024 AUT 5
$ ps -a Wrong command option
Submission Requirements: Clean up (remove) all the object files and executable files using the command make clean (in the directory where the Makefile is located). Then, in the parent directory of xv6-riscv, run the tar command to archive the whole xv6-riscv directory (with its sub-directories including user, kernel, and mkfs). Name this tar file q3-.tar where is your student ID.
The code you added/modified should be documented with appropriate comments. Make sure your name and student ID are part of your comments of any new functions in the xv6 code.
Note: Check that this tar file contains everything needed to recompile your modified xv6 before submitting. An empty file or one that could not compile will not receive any mark.

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 Programming Questions!