Operating Systems 2017F: Tutorial 6: Difference between revisions

From Soma-notes
Created page with "In this tutorial you will be running and modifying [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/lec16/newgetpid.zip newgetpid.c] from Operating Systems 2017F Lect..."
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
In this tutorial you will be running and modifying [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/lec16/newgetpid.zip newgetpid.c] from [[Operating Systems 2017F Lecture 16|Lecture 16]].
In this tutorial you will be running and modifying [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/lec16/newgetpid.zip newgetpid.c] from [[Operating Systems 2017F Lecture 16|Lecture 16]].  You will likely want to look at the Linux kernel source, particularly [http://elixir.free-electrons.com/linux/v4.4.83/source/kernel/sys.c kernel/sys.c].
 
==Tasks==
 
# Build and run newgetpid.c as demonstrated in Lecture 16 and as we did in the previous tutorial.
# What type is "current"?  How can you figure this out?
# Modify newgetpid.c so that it creates a device file /dev/describe rather than /dev/newgetpid.
# 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).
# '''(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 [http://elixir.free-electrons.com/linux/v4.4.83/source/kernel/signal.c#L2855 kill system call], and how it [http://elixir.free-electrons.com/linux/v4.4.83/source/kernel/signal.c#L1388 looks up the pid struct] and then [http://elixir.free-electrons.com/linux/v4.4.83/source/kernel/signal.c#L1303 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.

Latest revision as of 21:35, 12 November 2017

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.