Question: II . Reading from the / proc File System Once the process identifier has been stored, any reads from / proc / pid will return

II. Reading from the /proc File System
Once the process identifier has been stored, any reads from /proc/pid will return the name of the command, its process identifier, and its state. As illustrated in Section 3.1, the PCB in Linux is represented by the structure task_struct, which is found in the include file. Given a process identifier, the function pid_task() returns the associated task_struct. The signature of this function appears as follows:
struct task_struct pid_task(struct pid *pid,
enum pid_type type)
The kernel function find_vpid(int pid) can be used to obtain the struct pid, and PIDTYPE_PID can be used as the pid_type.
For a valid pid in the system, pid_task will return its task_struct. You can then display the values of the command, pid, and state. (You will probably have to read through the task_struct structure in to obtain the names of these fields.)
If pid_task() is not passed a valid pid, it returns NULL. Be sure to perform appropriate error checking to check for this condition. If this situation occurs, the kernel module function associated with reading from /proc/pid should return 0.
In the source code download, we give the C program pid.c, which provides some of the basic building blocks for beginning this project.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!