Refresher on Programs, Processes, and IPC
1 Operating Systems
- Everything you see here is required background for our discussion
of Android Internals and Security.
1.1 What is a program?
- Do NOT use "program" and "process" interchangeably.
- Precise def will be based on OS.
- A program is a file
- Executable permissions
- Structure of content rigidly defined by an executable format
- Linux: ELF, a.out, coff
- Windows: com, exe
- Java: .class files
- Android: .dex
- Program v Object code files
- generated by a linker
- On Linux, /usr/bin/ld (historically misnamed)
- The compiler/IDE tool chain invokes the linker
- Android APK file includes
- the .dex file
- many (20+?) other files describing resources.
- "App" is an alternate term for a program
1.2 What is a process?
- Process is a run-time volatile entity created by the OS system call
exec
- Processes have a virtual memory foot print.
- Code (machine instructions; historically misnamed as "text")
- Run time stack content
- Run time heap content
- Run time global variables
- Subject to paging and swapping
- Android details are more complex cf. Linux
1.3 Properties of a Process
- A program "does not run" – it justs sits somewhere on the disk.
- A process has a life cycle: is born, lives/runs for a while, dies.
- Every process has one parent.
- Obvious Exception: the very first process. Named:
init
- Parent is expected to out-live the child.
- Every process has a unique process-ID (pid) assigned to it by the
OS. Typically, 1 + pid of the last process born
- Every process is owned by a user. Typically the user who invoked
the correspnding program. But, see
suid
.
1.4 Processes v Threads
- Processes are disjoint from each other. Their address speaces are
disjoint. They are unaware of each other. OS schedules their
execution.
- 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.6 IPC: Message Passing
- P:: send(Q, e), value of expression e is sent to process Q
- Q:: receive(P, v), from P receive a msg, and store it in v
- asynchronous – non-blocking, sender sends and is off to his own work
- synchronous – blocking, sender waits for "got-it" ACK from
receiver
#include <sys/ipc.h>
#include <sys/msg.h>
- http://man7.org/linux/man-pages/man2/recv.2.html is for sockets,
not IPC
1.7 IPC: Shared Memory
- An area of memory A of process P is shared with Q
- Their addresses in P and Q may or may not be equal.
- Any writes of P are seen (read) by Q; and vice-versa
- Need to be careful: When does Q read? Before or after P has made changes?
- http://man7.org/linux/man-pages/man7/shm_overview.7.html
1.8 IPC: Synchronization
- All the following "loosely" (not rigorously) stated.
- Linux Semaphores (versus text book versions)
- Locks
- iNotify (tell me when a file or dir has changed)