Technical Women

001
Figure 1. Jean Bartik

Today

  1. File handles.

  2. Process life cycle:

    • Birth: fork()

    • Change: exec()

    • Death: exit()

    • The Afterlife: wait()

ASST1 Checkpoint

At this point:
  • If you have not started, you are behind.

  • If you don’t understand semaphores, you are behind.

  • If you have working locks, you’re a bit behind.

  • If you have working CVs, you’re OK.

  • Keep in mind: you need working locks and CVs for future assignments.

    • (The rest of the assignment is for points and won’t hurt you as much in the future.)

Announcement Questions?

$ pmap # memory mappings

pmap

bash

process bash 1

$ lsof # open files

lsof
True confessions: I cheated here.
  • /home/challen/.bashrc was not actually open when I ran this command.

  • bash didn’t have any interesting files open and I was embarrassed.

bashrc not open

Professor resorts to lying

$ lsof # open files

lsof
True confessions: I cheated here.
  • /home/challen/.bashrc was not actually open when I ran this command.

  • bash didn’t have any interesting files open and I was embarrassed.

Let’s imagine we caught bash during startup when it is reading its configuration parameters.

bash

process bash

Aside: the /proc/ file system

  • How do top, ps, pmap, lsof, and other process examination utilities gather information?

  • Linux reuses the file abstraction for this purpose.

procfilesystem

OK…​ Let’s Review

OS Abstraction Cheat Sheet

  • Threads save processor state.

  • Address spaces map the addresses used by processes (virtual addresses) to real memory addresses (physical addresses).

  • Files map offsets into a file to blocks on disk.

  • File-like objects look like files to a process but are not actually stored on disk and may not completely obey file semantics.

    • You can’t seek on a network socket or open certain network-mounted files.

  • Processes organize these other operating system abstractions.

Review: Abstractions

Abstractions simplify application design by:
  • hiding undesirable properties,

  • adding new capabilities, and

  • organizing information.

Review: Processes

Processes organize information about other abstractions and represent a single thing that the computer is "doing."

Processes contain:
  • one or more threads,

  • an address space, and

  • zero or more open file handles.

Review: Processes

  • Processes organize information about other abstractions and represent a single thing that the computer is "doing."

  • Processes contain:

    • one or more threads,

    • an address space, and

    • zero or more open file handles.

Review: Protection

One major operating system goal is to protect processes from each other.

So Now: Questions About Processes?

Updated Process Model

  • For today’s material being precise about how processes use files becomes important.

  • So let’s update our model. Here’s what we had last time:

process
  • So let’s update our model. Here’s what we had last time:

  • And here’s today’s change:

process updated

File Handles

  • The file descriptor that processes receive from open() and pass to other file system system calls is just an int, an index into the process file table.

  • That int refers to a file handle object maintained by the kernel.

  • That file handle object contains a reference a separate file object also maintained by the kernel.

  • Which then is mapped by the file system to blocks on disk.

  • So three levels of indirection:

    • file descriptor → file handle.

    • file handle → file object.

    • file object → blocks on disk.

  • Why?

Are you just trying

to confuse me?

Sharing File State

The additional level of indirection allows certain pieces of state to be shared separately.
  • File descriptors are private to each process.

  • File handles are private to each process but shared after process creation.

    • File handles store the current file offset, or the position in the file that the next read will come from or write will go to. File handles can be deliberately shared between two processes.

  • File objects hold other file state and can be shared transparently between many processes.

Operating System Design Principles

  • Separate policy from mechanism.

  • Facilitate control or sharing by adding a level of indirection.

Next Time

  • Continue with fork()

  • Begin talking about synchronization