Operating Systems 2017F: Tutorial 6

From Soma-notes

In this tutorial you will be running and modifying newgetpid.c from Lecture 16. You will likely want to look at the Linux kernel source, particularly kernel/sys.c.

Tasks

  1. Build and run newgetpid.c as demonstrated in Lecture 16 and as we did in the previous tutorial.
  2. What type is "current"? How can you figure this out?
  3. Modify newgetpid.c so that it creates a device file /dev/describe rather than /dev/newgetpid.
  4. Make /dev/describe output the calling process's parent ID (ppid), user ID (uid), group ID (gid), effective user ID (euid), and effective group ID (egid).
  5. (Advanced) Modify /dev/describe so that if you write a process ID to it, it will output the information on the provided process. To make this work, you'll need to:
    • Add a write method by adding a write operation to the file operations struct. Write operations have the same prototype as read operations, except the buffer is marked constant (because it shouldn't be modified).
    • Convert the written text to an integer and store in a global variable (to the module).
    • Find the right task struct. See the implementation of the kill system call, and how it looks up the pid struct and then gets the right task struct using that pid struct.
    • After returning info on the selected process, further calls should return info on the current process. You can do this by setting the global process ID to 0 and checking this value, using the current task if it is zero.