Skip to content

Using system calls to implement the top command in the XV6 Operating System. 'top' is a basic Unix command which provides a dynamic real-time view of the running system.

License

Notifications You must be signed in to change notification settings

samyukthagopalsamy/Top_command_in_Xv6_OperatingSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using system calls to implement the top command in the XV6 Operating System XV6 is a simple Unix-like teaching operating system, developed by MIT.
It is an implementation of the Unix version 6 using ANSI C language for x86 platforms.
top is a basic Unix command which provides a dynamic real-time view of the running system. The goal of this project is to include the top command in the XV6 environment, similar to that of the one in Linux. This is done by developing a user program which includes system calls to display the list of processes, users of the system resources and the summary information of the system.
The user program included in xv6 displays the Pid, process name, the status of the processes, parent id, and memory size.

Follow
The xv6 operating system is run on a QEMU virtual machine on top of a 64-bit Ubuntu 18.04.1 LTS machine.
The following tools and packages are to be installed on the Ubuntu Linux system:

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install multi-lib
sudo apt-get install qemu
sudo apt-get install git

In case of a 64-bit OS, there is a chance that the Makefile will not be able to find qemu. In that case, you should edit the Makefile at line 54 and add the following code:
QEMU = qemu-system-x86_64

Install xv6 by creating a directory, and clone xv6 to that directory:
$ git clone git://github.com/mit-pdos/xv6-public.git

Compile xv6:
$make

Compile and run the Qemu emulator:
$make qemu

This will start up a window with QEMU emulator and will start the shell prompt of the xv6 operating system.

System call used:

New system call named sys_top() and sys_date() are included in xv6. To add a system call that can be called in xv6's shell, some changes in the following files have to be made:
• sysproc.c - the real implementation of the method is added here
• syscall.h - the position of the system call vector that connects to the implementation is defined here
• user.h - the function that can be called through the shell is added here
• usys.S - use the macro to define connect the call of the user to the system call function

  1. The system call sys_top( ) is included in the file proc.c
  2. #define sys_top 24 is included in the file syscall.h
  3. The function void top (void) is added under the system calls in the file user.h
  4. The function syscall(top) is added in the file usys.S

Since the permission for accessing the p table was denied, the sys_top() system call is included in the file proc.c instead of the file sysproc.c
The included system call sys_top( ) iterates the p-table and gets the pid, process name, status of the processes and the memory size.
By using the system call sys_top( ) the following system information are successfully displayed:
• Current time, number of users.
• Total number of tasks running.
• Memory statistics – total physical memory present, free and used.
• PID and the corresponding Process name
• Memory size (KiB)
• %MEM and Total memory used by the processes
• State of the processes (running, sleeping, zombie, runnable, unused)

The system information listed above is obtained as follows:

  1. The current system time is obtained using the date system call included in Xv6.
  2. RES is obtained from proc of individual process.
  3. %MEM is obtained by the formula: %mem = (RES / total memory) * 100%. The total physical memory in xv6 is constant which is 0xE000000 (224 MB)
  4. STATE and PID of processes are obtained from proc of current processes which are present in the ptable . ptable can hold a maximum of 64 processes as defined .
    dd

About

Using system calls to implement the top command in the XV6 Operating System. 'top' is a basic Unix command which provides a dynamic real-time view of the running system.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published