Question
write Program in C to Add System call. Header File: #include struct pinfo { pid_t pid; /* process id */ long state; /* current state
write Program in C to Add System call.
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 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 */
};
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);
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
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
There are 3 Steps involved in it
Step: 1
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