Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add a Static System Call to the Linux Kernel Write a new static system call to incorporate to your custom Linux Kernel. The system call

Add a Static System Call to the Linux Kernel

Write a new static system call to incorporate to your custom Linux Kernel. The system call you write should take one argument and return the process state information for that process, its child processes, child threads and sibling processes. The prototype for your system call will be:

asmlinkage long sys_pinfo(struct pinfo *info);

pid_t is defined in /usr/include/sys/types.h and /usr/include/linux/types.h for user-space programs and in /usr/src/linux/include/linux/types.h (/usr/src/linux/include/uapi/asm-generic/posix_types.h) for kernel-space routines.

Also see /usr/include/asm-generic/posix_types.h

Define struct pinfo in /usr/src/linux/include/linux/pinfo.h as part of your solution (localize it for your test C program):

#include

struct pinfo {

pid_t pid; /* process id */

long state; /* current state of process */

long nice; /* process nice value */

pid_t parent_pid; /* process id of parent */

int nr_children; /* total number of child processes */

int nr_threads; /* total number of child threads */

pid_t youngest_child_pid; /* pid of youngest child */

pid_t younger_sibling_pid; /* pid of younger sibling */

pid_t older_sibling_pid; /* pid of older sibling */

unsigned long start_time; /* process start time */

long user_time; /* CPU time spent in user mode */

long sys_time; /* CPU time spent in system mode */

long cutime; /* total user time of children */ long cstime; /* total system time of children */

long uid; /* user id of process owner */

char comm[16]; /* name of program executed */

};

Sibling processes are those sharing the same parent. Younger, youngest and older comparisons between processes are made based on their start time.

Your system call should return 0 unless an error occurs. Your code should handle errors that can occur but not handle any errors that cannot occur. At a minimum, your system call should detect the following conditions and respond as described:

If the address for the pinfo structure is null, return -22.

If a value to be set in pinfo is accessible through a pointer which is null, set the corresponding field value in pinfo to -1. For example, the youngest_child_pid should be set to -1 if the process does not have a child. The referenced error code is defined as EINVAL in /usr/src/linux/include/uapi/asm-generic/errno-base.h /usr/src/linux/include/linux/errno.h /usr/src/linux/usr/include/asm/errno.h.

Each system call must be assigned a number which becomes its position in the system call vector. You must identify an available spot for your new system call in the vector for x86_64 system calls (see /usr/src/linux/arch/x86/syscalls/syscall_64.tbl and /usr/src/linux/include/uapi/asm-generic/unistd.h)

Linux maintains a list of all processes in a doubly linked list. Each entry in this list is a task_struct structure, which is defined in /usr/src/linux/include/linux/sched.h.

In /usr/src/linux/include/asm-generic/current.h, current is defined to inline a function which returns the address of the task_struct of the currently running process. All of the information to be returned in the pinfostructure can be determined by starting with current. Note that current.h includes /usr/src/linux/include/linux/thread_info.h

See /usr/src/linux/arch/x86/include/asm/thread_info.h

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago