Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi im customizing the linux kernel and my assignment is to add a static system call to the linux kernel as well as test my

Hi im customizing the linux kernel and my assignment is to add a static system call to the linux kernel as well as test my system kernel, ive finished everything along with my makefile but did my makefile differently than the way we were instructed and just want to test verything runs smoothly before submission, below is my system call code, test code, makefile, instructions on how to run and expected output. the problem is I decided to use virtual box and am having troube running it, could someone please run it and shows screenshots of what you get as well as details on how you ran it, our output is supposed to look like the expected outputs provided below. please help

pinfo.c

---------------------------------------------------------------------------------------------------------------------

#include #include #include #include #include #include #include #include

#define NSEC 1000000000 #define time_cal(t) \ t->start_time.tv_sec * NSEC + t->start_time.tv_nsec

// Prototype functions int get_PID(void); long get_state(void); long get_nice(void); unsigned long get_start_time(void); int get_parent_id(void); int get_children(void); int get_youngest_child(void); int get_younger_silbing(void); int get_older_sibling(void); long get_user_time(void); long get_sys_time(void); char * get_comm(void); long get_UID(void);

// Global var used to get the task struct struct task_struct *get_t;

// Process ID int get_PID(void){ return get_t->pid; }

// Current state of process (-1 unrunnable, 0 runnable, >0 stopped) long get_state(void){ return get_t->state; }

// Process nice value range from -20 <> 19 (high prio neg values & lower prio pos values) long get_nice(void){ return (get_t->prio - MAX_RT_PRIO - 20); }

// Process id of parent int get_parent_id(void){ return get_t->parent->pid; }

// Total number of children int get_children(void){ struct list_head *tmp; int i = 0; // Traverse the doubly linked list to get the number of children list_for_each(tmp, &get_t->children){ ++i; } // no children then return -1 if(i == 0){ return -1; } else{ return i; } }

// PID of the youngest child int get_youngest_child(void){ // get the list of childrens struct list_head *tmp = &get_t->children; int pid; if(&tmp == NULL){ return -1; } // use macro to get the task_struck embedded // Note: list_entry( ptr, type, member) pid = list_entry(tmp->prev, struct task_struct, children)->pid; // if list_entry ret is zero or the pid is the same as its self then return -1 if(pid == 0 || pid == get_PID()){return -1;} return pid; }

// PID of younger sibling int get_younger_sibling(void){ // get the list of siblings struct list_head *tmp = &get_t->sibling; int pid; if(&tmp == NULL){return -1;} // use macro to get the task_struck embedded // Note: list_entry( ptr, type, member) pid = list_entry(tmp->next, struct task_struct, sibling)->pid; // if list_entry ret is zero or the pid is the same as its self then return -1 if(pid == 0 || pid == get_PID()) {return -1;} return pid; }

// PID of older sibling int get_older_sibling(void){ // get the list of sibling struct list_head *tmp = &get_t->sibling; int pid; if(&tmp == NULL){return -1;} // use macro to get the task_struck embedded // Note: list_entry( ptr, type, member) pid = list_entry(tmp->prev, struct task_struct, sibling)->pid; // if list_entry ret is zero or the pid is the same as its self then return -1 if(pid == 0 || pid == get_PID()) {return -1;} return pid; }

// Process start time unsigned long get_start_time(void){ return time_cal(get_t); }

// CPU time spent in user mode long get_user_time(void){ return get_t->utime; }

// CPU time spent in system mode long get_sys_time(void){ return get_t->stime; }

// User id of process owner long get_UID(void){ return get_t->uid; }

// Name of program executed char * get_comm(void){ return get_t->comm; }

asmlinkage long sys_pinfo(struct pinfo *process){ // if the user didn't provide stack or heap space then return -22 if(&process == NULL){return -22;} // Fill in the Process Information get_t = get_current(); process->pid = get_PID(); process->state = get_state(); process->nice = get_nice(); process->parent_pid = get_parent_id(); process->children = get_children(); process->youngest_child_pid = get_youngest_child(); process->younger_sibling_pid = get_younger_sibling(); process->older_sibling_pid = get_older_sibling(); process->start_time = get_start_time(); process->user_time = get_user_time(); process->sys_time = get_sys_time(); process->uid = get_UID(); strcpy(process->comm, get_comm());

return 0; }

-------------------------------------------------------------------------------

test_pinfo.c

------------------------------------------------------------------------------------

#include #include #include #include "pinfo.h" #include #include

#define __NR_pinfo 301

int main(void){

struct pinfo p_info; int status = 1;

status = syscall(__NR_pinfo, &p_info);

printf("CURRENT PROCESS INFORMATION "); printf("----------------------------------------------- "); printf("PID:\t\t\t%i ",p_info.pid); printf("STATE:\t\t\t%ld ", p_info.state); printf("NICE:\t\t\t%ld ", p_info.nice); printf("PARENT PID:\t\t%i ", p_info.parent_pid); printf("NUMBER OF CHILDREN: \t%i ",p_info.children); printf("YOUNGEST CHILD (PID): \t%i ", p_info.youngest_child_pid); printf("YOUNGER SIBLING (PID):\t%i ", p_info.younger_sibling_pid); printf("OLDER SIBLING (PID):\t%i ", p_info.older_sibling_pid); printf("START TIME (nanosecs):\t%lu ", p_info.start_time); printf("USER TIME (millisecs): \t%ld ", p_info.user_time); printf("SYSTEM TIME (millisecs):%ld ", p_info.sys_time); printf("UID (user id):\t\t%ld ", p_info.uid); printf("COMM (program name):\t%s ", p_info.comm);

return 0; }

------------------------------------------------------------------------------------

Makefile

------------------------------------------------------------------------------------

all: test

test: test_pinfo.o gcc test_pinfo.o -o test

test.o: test_pinfo.c gcc -c test_pinfo.c

clean: rm -rf *.o test

------------------------------------------------------------------------------------------------------

expected output with 3 tests

--------------------------------------------------------------------------------------------------------

Output Collected:

Test#1: No siblings or children

CURRENT PROCESS INFORMATION ----------------------------------------- PID: 2948 STATE: 0 NICE: -1 PARENT PID: 2852 NUMBER OF CHILDREN: -1 YOUNGEST CHILD (PID): -1 YOUNGER SIBLING (PID): -1 OLDER SIBLING (PID): -1 START TIME (nanosecs): 731633090922 USER TIME (millisecs): 6 SYSTEM TIME (millisecs): 6 UID (user id): 0 COMM (program name): test

Test#2: Siblings [root@localhost test_pinfo]# sleep 1 & sleep 1 & ./test & sleep 1 & sleep 1 [1] 2951 [2] 2952 [3] 2953 [4] 2954 CURRENT PROCESS INFORMATION ----------------------------------------- PID: 2953 STATE: 0 NICE: -3 PARENT PID: 2852 NUMBER OF CHILDREN: -1 YOUNGEST CHILD (PID): -1 YOUNGER SIBLING (PID): 2954 OLDER SIBLING (PID): 2952 START TIME (nanosecs): 773127019922 USER TIME (millisecs): 4 SYSTEM TIME (millisecs): 19 UID (user id): 0 COMM (program name): test

Test#3: Children (with fork() in test file) PID: 3090 STATE: 0 NICE: 0 PARENT PID: 2852 NUMBER OF CHILDREN: 1 YOUNGEST CHILD (PID): 3091 YOUNGER SIBLING (PID): -1 OLDER SIBLING (PID): -1 START TIME (nanosecs): 1326266085922 USER TIME (millisecs): 2 SYSTEM TIME (millisecs): 2 UID (user id): 0 COMM (program name): test

PID: 3091 STATE: 0 NICE: -1 PARENT PID: 3090 NUMBER OF CHILDREN: -1 YOUNGEST CHILD (PID): -1 YOUNGER SIBLING (PID): -1 OLDER SIBLING (PID): -1 START TIME (nanosecs): 1326240760922 USER TIME (millisecs): 4 SYSTEM TIME (millisecs): 7 UID (user id): 0 COMM (program name): test

-----------------------------------------------------------------------------------

instructions on how to run

---------------------------------------------------------------------------------

Instructions for running the test program and file locations: Location of pinfo.c: /usr/src/linux/pinfo/

Location of kernel space pinfo.h: /usr/src/linux/include/linux/

Location of user space pinfo.h: /root/Desktop/proj2/

Location of test_pinfo.c: /root/Desktop/proj2/

Location of Makefile of test_pinfo.c: /root/Desktop/proj2/

The program can be run by navigating to /root/Desktop/proj2 and entering ./test into bash

By default, the test file will call the static system call and print the information for the calling process. To test whether the siblings PIDs are calculated properly, the following tests in bash can be done:

sleep 1 & ./test or sleep 1 & ./test & sleep 1 or ./test & sleep 1

To test whether the children fields are calculated properly, a simple fork() inserted in the test file will suffice and a sleep(). For more information, please refer to expected output

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

Mysql Examples Explanations Explain Examples

Authors: Harry Baker ,Ray Yao

1st Edition

B0CQK9RN2J, 979-8872176237

More Books

Students also viewed these Databases questions

Question

Describe the five elements of the listening process.

Answered: 1 week ago