2015-08-10 Top | Slides

Refresher on Programs, Processes, and IPC

Table of Contents

1 Operating Systems

  1. Everything you see here is required background for our discussion of Android Internals and Security.

1.1 What is a program?

  1. Do NOT use "program" and "process" interchangeably.
  2. Precise def will be based on OS.
  3. A program is a file
    1. Executable permissions
    2. Structure of content rigidly defined by an executable format
      1. Linux: ELF, a.out, coff
      2. Windows: com, exe
      3. Java: .class files
      4. Android: .dex
  4. Program v Object code files
    1. generated by a linker
    2. On Linux, /usr/bin/ld (historically misnamed)
  5. The compiler/IDE tool chain invokes the linker
  6. Android APK file includes
    1. the .dex file
    2. many (20+?) other files describing resources.
    3. "App" is an alternate term for a program

1.2 What is a process?

  1. Process is a run-time volatile entity created by the OS system call exec
  2. Processes have a virtual memory foot print.
    1. Code (machine instructions; historically misnamed as "text")
    2. Run time stack content
    3. Run time heap content
    4. Run time global variables
    5. Subject to paging and swapping
  3. Android details are more complex cf. Linux

1.3 Properties of a Process

  1. A program "does not run" – it justs sits somewhere on the disk.
  2. A process has a life cycle: is born, lives/runs for a while, dies.
  3. Every process has one parent.
    1. Obvious Exception: the very first process. Named: init
    2. Parent is expected to out-live the child.
  4. Every process has a unique process-ID (pid) assigned to it by the OS. Typically, 1 + pid of the last process born
  5. Every process is owned by a user. Typically the user who invoked the correspnding program. But, see suid.

1.4 Processes v Threads

  1. Processes are disjoint from each other. Their address speaces are disjoint. They are unaware of each other. OS schedules their execution.
  2. A thread is part of a process. Typically, several threads share a process. Address space is overlapping. The language (eg., Java) runtime schedules the execution.

1.5 Inter Process Communication (IPC)

  1. All the following is via Operating System Calls (syscalls)
  2. Read: http://man7.org/conf/lca2013/IPC_Overview-LCA-2013-printable.pdf
  3. Read: http://www.tldp.org/LDP/tlk/ipc/ipc.html from The Linux Documentation Project

1.6 IPC: Message Passing

  1. P:: send(Q, e), value of expression e is sent to process Q
  2. Q:: receive(P, v), from P receive a msg, and store it in v
  3. asynchronous – non-blocking, sender sends and is off to his own work
  4. synchronous – blocking, sender waits for "got-it" ACK from receiver
  5. #include <sys/ipc.h>
  6. #include <sys/msg.h>
  7. http://man7.org/linux/man-pages/man2/recv.2.html is for sockets, not IPC

1.7 IPC: Shared Memory

  1. An area of memory A of process P is shared with Q
  2. Their addresses in P and Q may or may not be equal.
  3. Any writes of P are seen (read) by Q; and vice-versa
  4. Need to be careful: When does Q read? Before or after P has made changes?
  5. http://man7.org/linux/man-pages/man7/shm_overview.7.html

1.8 IPC: Synchronization

  1. All the following "loosely" (not rigorously) stated.
  2. Linux Semaphores (versus text book versions)
  3. Locks
  4. iNotify (tell me when a file or dir has changed)

1.9 IPC: Mutual Exclusion

  1. A sequence S1 of code lines of P1 shoud not be in execution while S2 of P2 is, and vice versa
  2. Progress in computation: 4 requirements
  3. Difference between mutual-exclusion and synchronization

1.10 Silbershatz and Galvin book Linux Slides

  1. ./LinuxOS-SGOSbookCh20.ppt Linux chapter from Silbershatz and Galvin book.

Copyright © 2014 pmateti@wright.eduwww.wright.edu/~pmateti 2015-08-10