Quantcast
Channel: Active questions tagged linux-kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 12294

Get Process Info (Current proc, parent proc, oldest child proc)

$
0
0

I have an exercise about adding a system call in the Linux kernel, but I'm struggling to implement it. Below is the description:

The main part of this assignment is to implement a new system call that lets the user determine the information about both the parent and the oldest child process. The information about the processes' information is represented through the following struct:

struct procinfos{
    long studentID;
    struct proc_info proc;
    struct proc_info parent_proc;
    struct proc_info oldest_child_proc;
};

Where proc_info is defined as follows:

struct proc_info{
    pid_t pid;
    char name[16];
};

procinfos contains information of three processes:

  • proc, the current process or process with PID
  • parent_proc, the parent of the first process
  • oldest_child_proc, the oldest child process of the first process

The processes' information is stored in the struct proc_info and contains:

  • pid, the pid of the process
  • name, the name of the program which is executed

The prototype of our system call is described below:

To invoke get_proc_info system call, the user must provide the PID of the process or −1 in the case of the current process. If the system call finds the process with the given PID, it will get the process' information, put it in output parameter *info, and return 0. However, if the system call cannot find such a process, it will return EINVAL.

#include <linux/kernel.h>
#include <unistd.h>
struct procinfos{
    long studentID;
    struct proc_info proc;
    struct proc_info parent_proc;
    struct proc_info oldest_child_proc;
};
struct proc_info{
    pid_t pid;
    char name[16];
};
asmlinkage long sys_get_proc_info(pid_t pid, struct proinfos *info){
// TODO: implement the system call
}

HINT:

  • To find the current process: look at arch/x86/include/asm/current.h or for simple use macro current (current -> pid).
  • To find info about each process, look at include/linux/sched.h.
  • To after the trimming process the time to build the kernel is reduced to about 10 minutes but it is till a long time to compile. To make to the development of system call as fast as possible, you can use kernel module to test the system call represented as a module in advance (Appd B).

How to implement this system call?


Viewing all articles
Browse latest Browse all 12294

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>