Operating Systems 2017F Lecture 19

From Soma-notes

Video

[1]

Notes

In Class

Lecture 19
----------

Where's main?

* lots of programs have "main" functions - a function that runs first and controls the execution of the program
* Do these have "main" functions? In what sense?
  - Linux kernel modules
  - FUSE applications?
  - the Linux kernel?
  - node web applications?

In many systems, "main" just sets up event handlers
 - the event loop can be implicit or explicit
   - or there may be no loop at all, just handlers and "interrupts" of some kind
 - event loops poll (check) to see when there are new events


OS kernels are essentially the same thing


Additional Notes:

Important notes: How can you recover a filesystem? How do you delete a file? What is a filesystem?:

  • persistent data structure
  • stored in fixed-sized blocks (at least 512 bytes in size)
  • maps hierarchical filenames to file contents
  • has metadata about files (somwhow)

What is in a filesystem?

  • data blocks
  • metadata blocks

How do you organize metdata: 1) First you must identify characteristics of the file system Superblock : summary y block which tells you about the other blocks you have and it depends on which file system you have. It’s usually the first block of a file system. In the superblock? : 1) What kind of file system is this? By checking what is the magic number it has 2) How big is the file system? 3) How is it organized? 4) Where can I find the rest of the metadata?

  • How can you identify which file system it is from looking at the super class

-> google “magic number of a file” -> ex: jpg ctr^c ctr^c : switched the pictures into a binary file -> look at the beginning of the file you will see JFIF: first several bytes in general that identifies the type of the file (magic number) File extension :  what is it ?  is it important  the kernel does not know and not care about it

For POSIX file systems: -.> file metadata is stored in inodes -.> most have pre-reserved inodes

  -> the only way you can run out of inodes if you keep creating small files 

Usenet : al the things you use to post messages thro social media, email, etc. Those were made using Usenet. Like email but Local Usenet server. But it died over time. Every message is stored in an individual file.



Important commands: File * : to identify the kind of file system 1. As : Run dumpe2fs foo. What does the output of this command mean?  Does this give you info about the file system?  File bar : bar is the file name and cp comp3000-midterm-2017.pdf bar  Evince bar : opens up the pdf file

Additional Notes

Where's main?

  • lots of program shave "main" functions - a function that runs first and controls the execution of the program
  • Do these have "main" functions?
    • Linux kernel modules
    • FUSE applications?
    • the linux kernel?
    • node web applications?


In many systems, "main" just sets up even handlers

  • the event loop can be implicit or explicit
    • or there may be no loop at all, just handlers and "interrupts" some kind
  • event loops poll (check) to see when there are new events
  • what are event loops for node app?
    • where are interrupts for node apps?
      • Incoming network requests, it's an event

Code run differently in the kernel :

1)functions runs on the bhealf of insmod, unles sit is Independence context

2)codes that run on the bhelaf o the process


3)after an interrupt: no process , it is an interrupt cotext

4) file names : regular programs but the square brackets, execution context + address space. they share the kernel's address space, they are called kernel threads which are independently scheduling . You can not kill them but you can change their scheduling , maybe their priority but not 100%.

does it create a proces? no , but it can create a kernel thread (is it a process? virtual adress space, .
multi- threaded: maintains multiple address processes , ex: fire fox.

ps -elF | less "number" : displays threads.

top : displays all the processes

ls time : shows you the time .

sys: how much time in the kernel space real: how much time user : how much time in user space

process : can't manipulate its own memory map directly, it has an address space, but cant change it. Process: is limited but the kernel is not and the kernel can change it's own address and in charge of its self.

Kernel tasks : are threads, when a process makes a system call , thi sis schedules in the process priority.



When running
"time ls"
real = realtime it took to run user = the user space time sys = kernel time


What's flow of control in tutorial 7?
What is the connection?
To exit the program, we must unmount the filesystem, run "sudo umount mnt"


OS kernels are essentially the same thing


what is the flow of control ? what connection between things we are doing in the new terminal and the old one

-> these programs are communicating to each other, it will be invoked when we use mnt (mount) the kernel knows it is a filesystem , process runs system calls, then kernel talks to out original terminal. How? you can use strace to know, it is waiting to be invoked, to receive and responds to messages. events will be passed off to another process. switching between one process to another. it has potential security benefits.

Key to understand this tutorial :

-> understand net flow control.

-> how do processes communicate?

-> how does it take a directory int and creates a filesystem from it?:

      • sub tree starting at mount is delegated to this process.
      • permissions are limited

How to kill it?

-> ctrl c , no , you can but the kernel will be unhappy.
-> unmount the file system when you are done using it
-> umount / you have to do it as root

Node web applications

  • Theres not a dedicated main function but its the first thing that runs
  • Every line in the node application terminates
  • If you start a web server, the function call starting it will terminate
  • Whats running? The main has finished. Is the program doing anything actively if theres no external input?
  • In many systems main just sets up event handlers
  • The event loop can be implicit or explicit
  • Its possible to have no loop at all just handlers and interrupts of some kind
  • Event loops check to see when there are new events
  • Os kernels behave the same way as node applications
  • Waiting for events


What happens when you use insmod?

  • In newgetpid: Init and exit are called when the insmod program makes system calls to load the module
  • Init is run on behalf on insmod
  • Kernel code fits into 3 categories
    • Code that runs on behalf of a process
    • Code that runs after an interrupt
    • Kernel threads, has lots of functionality


Why is a kernel thread not a process?

  • The kernel maintains its own address space
  • Has its own virtual address map
  • The kernel always has just 1 address space regardless of how many threads there are
  • Processes cannot manipulate its own memory map directly, needs to ask kernel first
  • Processes are limited, the kernel is not, has control over itself


  • Kernel tasks = kernel threads
  • Independently scheduled
  • Once we call insmod everything happens in user space
  • Strace uses a system call called ptrace


Tutorial 7: Fuse

  • Memoryll.py program
  • Always unmount a filesystem when youre done using it
  • No class Thursday! no office hours on Wednesday

Lecture 19

Where's main?

  • lots of programs have "main" functions - a function that runs first and controls the execution of the program
  • do these have "main" functions?
  • Linux kernel modules?
  • FUSE applications?
  • the Linux kernel?
  • node web applications?
In many systems, "main" just sets up event handlers
  • the event loop can be implicit or explicit
  • or there may be no loop at all, just handlers and "interrupts" of some kind
  • event loops poll (check) to see when there are new events
OS kernels are essentially the same thing -> just sitting around waiting for an event
  • when an event happens -> do something
  • in this case events = interrupts, generally
  • insmod exec. is execve(), new binary, makes system calls to load new module
  • init, called when insmod makes systemcalls to load new module
  • as part of loading a module, run the function that makes the necessary system calls
  • see static int __init newgetpid_init(void) -> soma notes
  • there is no process... it's an interrupt context --> check in context of assignment
  • the kernel maintains its own address space for all kernel operations... it has its own virtual address map... every process has its own address space, which is created every time a process is created
  • try stracing insmod to see what system calls are being made (Openbox, not on live system)

Tut 7

  • if you make a new directory inside /mnt it doesn't affect it
  • what's the control flow here?
  • program running is a kernel interface talking to another kernel interface
  • kernel is handing off anything that happens in /mnt to the running python process
  • the kernel talks to the new filesystem in ../../../mnt, which is waiting for events (waiting to be invoked)
  • classic microkernel architecture
  • understand the flow of control... what is the kernel doing?
  • what does it mean to have a filesystem implemented