Question
Header File: #include struct pinfo { pid_t pid; /*process id */ long state; /*current state of process */ long nice; /*process nice value */ pid_t
Header File:
#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 ofyoungest child */
pid_t younger_sibling_pid; /* pid ofyounger sibling */
pid_t older_sibling_pid; /* pid ofolder sibling */
unsigned long start_time; /* processstart 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 */
};
Add a Static System Call to the LinuxKernel
Write a new static system call to incorporate to your customLinux Kernel. The system call you write should take one argumentand return the process state information for that process, itschild processes, child threads and sibling processes. The prototypefor your system call will be:
asmlinkage long sys_pinfo(struct pinfo *info);
Sibling processes are those sharing the same parent. Younger,youngest and older comparisons between processes are made based ontheir start time.
Your system call should return 0 unless an error occurs. Yourcode should handle errors that can occur but not handle any errorsthat cannot occur. At a minimum, your system call should detect thefollowing 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 apointer which is null, set the corresponding field valuein pinfo to -1. For example,the youngest_child_pid should be set to -1 if the processdoes not have a child. The referenced error code is defined asEINVAL in /usr/src/linux/include/uapi/asm-generic/errno-base.h
struct pinfo;
#include
#include
#include
#include
#include
#include
#include
#include
#include
…
asmlinkage long sys_pinfo(struct pinfo *info)
{
// Local Declarations
…
if(info == NULL)
return -22;
// Main Logic
…
return 0;
}
If the address for the pinfo structure is null, return-22.
Step by Step Solution
3.54 Rating (161 Votes )
There are 3 Steps involved in it
Step: 1
To add a static system call to the Linux kernel you need to follow a series of steps Below is a simplified example to help you get started Note that k...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started