GOAT EngineerPreparing your learning space…

System Design · Concept Library · Free article

A Program Becomes a Process

Follow two image jobs through address spaces, owned resources, explicit communication and a crash.

A program is stored instructions and data. A process is a running instance with execution state, an address space and operating-system-managed resources. Two jobs inside one process can communicate through shared memory, but they also share a failure boundary. Separate processes isolate ordinary memory access and many failures, so data must cross through an explicit mechanism such as a copied message.

The file on disk is not the running job

Suppose image-worker is a program stored on disk. It contains instructions and initial data. Starting it asks the operating system to create a process, a running instance of that program. The process needs execution state, memory it can address and records for resources it has opened.

Running the same program twice can create two processes. They begin from the same instructions but acquire separate runtime state. One can be processing photo-a.jpg while the other works on photo-b.jpg. Editing a file on disk and changing a live process are also different actions.

The operating system identifies and manages the running instances. On Linux, /proc/<pid>/status exposes fields such as process state, memory totals and the number of threads. Those observations are implementation-specific details of Linux, while the program-versus-process distinction applies more broadly.

The image worker before and after launch
QuestionProgramProcess
What is it?Stored instructions and initial dataOne running instance
Does it have live memory?No process address space by itselfYes, under the operating system model
Can there be several?One program file can be reusedEach launch can create another instance
Can it own an open handle?No live handle tableYes, while the process exists

Follow one launch from your function to the CPU

Imagine the worker begins with pixels = loadImage(path), then calls makeThumbnail(pixels). The file containing those functions is the program. The array created for this particular photo belongs to a running instance. Launch a second worker for another photo and it needs its own array, current function calls and place in the instructions. Sharing the program file does not merge those live values.

To start an executable, the OS arranges mappings for its code and data, prepares a stack for the first thread, supplies startup information such as arguments, and makes that thread ready to run. The stack records active calls and local values; the instruction pointer records where execution continues. A language runtime or executable startup routine may run before your own first function. Mapping a program does not require eagerly copying its entire file into RAM. In the visual machine, a page is one small unit of mapped memory; a physical frame is the RAM slot that holds a resident page. Watch the mappings appear before those frames fill.

The loader creates code, data, heap and stack mappings, prepares startup arguments and queues a ready thread. Only accessed file-backed pages become resident in this model. Enable JavaScript to build the process step by step.

When the scheduler gives the thread a CPU turn, makeThumbnail can execute its loops. When that turn ends, the OS preserves the execution context so the thread can resume. That is how the same core can make progress on two running instances without confusing their arrays or return addresses. A process exists while its threads wait too; running instance does not mean occupying a core at every instant. The next machine reduces this function to a three-pixel transform, output[i] = pixels[i] / 2, so its loop state fits on screen. It is a stand-in for work inside a thumbnail pipeline, not an image-resizing algorithm.

Two image workers use one CPU. Saving and restoring the instruction pointer, loop index and stack pointer preserves each turn; their arrays and call stacks remain in separate process memory. Enable JavaScript to switch, block and wake the workers.

The boundary experiments switch from two thumbnails to a thumbnail/index pipeline
Code-level jobLab nameState it needs
Make a thumbnailalpha / worker-aPhoto A, a 16-byte result and handle A
Build the search indexbravo / worker-bPhoto B, a received result and handle B

An address only makes sense inside its address space

A process ordinarily uses a virtual address space, the set of addresses its code can name under the operating system's memory mapping. If the thumbnail job says its result begins at address 0x1200, that number identifies a location in its own mapping. Giving the number to a separate process does not grant access to the same bytes.

This is why a raw pointer is not an inter-process message. The sender and receiver need an explicit communication mechanism. A pipe, local socket or other inter-process communication channel can carry bytes. Shared-memory mappings are also possible, but they are created explicitly and require coordination. The workbench models one simple option: copy a 16-byte result into a message owned by the receiver.

Inside one process, threads can refer to the same process memory. That can avoid a message copy, but it changes the isolation boundary. The next lesson examines that sharing in detail.

Suppose worker-a creates a result array. Its first value, result[0], is at address 0x1200. This address is a number that worker-a uses to find that value in its own memory.

Now suppose worker-a sends only the number 0x1200 to worker-b. It has not sent the value stored there. It has only sent an address.

Worker-b has its own memory. When worker-b reads address 0x1200, it looks in its own memory, not worker-a's. That address might contain a different value. Or it might not be a valid address for worker-b, in which case the read can cause a memory-access error. Receiving the address does not give worker-b access to worker-a's result.

To give worker-b the result, worker-a can send the data itself. In this example, the complete result takes 16 bytes. Worker-a sends those bytes in a message. Worker-b receives them and stores its own copy.

Once worker-b has received the copy, it no longer needs worker-a's memory to read that result. If worker-a then crashes, worker-b still has its copy and can keep working. But if worker-a crashes before the result is copied, separating the processes does not recover the missing data.

The lab always copies the result before the crash. It also shows an explicit error when worker-b tries to use worker-a's address. That error is a teaching aid: on a real machine, an ordinary pointer is just an address value. It does not carry a label saying which process it came from.

Enable JavaScript to compare the two choices in the compact concept diagram. The worked examples explain the same process boundary, scratch ownership, CPU schedule or pending-I/O consequence without requiring the interactive.

The boundary groups memory, handles and failure

Our process owns an address space and two modeled handles, one for each image job. A handle is a process-visible identifier the operating system uses to refer to an opened resource. Unix-like systems commonly use file descriptors for files, pipes, sockets and some devices.

When the modeled process crashes, its address space and handles are reclaimed together. If both jobs are inside that process, both stop. The index job cannot keep executing after the process that contained its thread no longer exists. If each job runs in a separate process, the thumbnail crash can leave the index process intact.

This is useful isolation, not an absolute promise that failures never spread. Two processes can still depend on the same disk, machine, parent supervisor or shared-memory region. Resource exhaustion and operating-system failure can affect both. State the boundary you created and the dependencies that remain outside it.

Creation, running, exit and cleanup form a lifecycle

A process moves through a lifecycle. The operating system creates its records and address space, makes its threads eligible to run, schedules their CPU work, blocks them when they wait and records termination. A parent or supervisor may inspect the exit status and decide whether to restart the work.

Termination must settle owned resources. The teaching model releases process-owned memory and handles on its modeled crash. It does not claim that application-level work was rolled back. A file write already completed, a message already sent or a remote request already accepted may outlive the process. Process cleanup and business-effect rollback are separate questions.

On Unix-like systems, fork and exec separate two operations often hidden behind a launch command. fork creates a child process; exec replaces the calling process's program image and normally keeps its process ID. A child can initially see the same memory values through copy-on-write mappings, but an ordinary private-memory write does not update its parent's copy. This is why program and process are distinct even after startup.

Exit also has two parts: execution and most owned resources end, while a small exit-status record may remain until a parent waits for it. That record is the basis of a zombie process on Unix-like systems. It is not a still-running image worker. Our lab stops at resource reclamation and does not simulate parent/child reaping.

Ungraded transfer checks

Can two launches of the same program share a process ID?
They are separate process instances and need distinct live identities. The operating system may reuse an ID after an earlier process has ended, so the number is not a permanent identity.
Why can't worker-b dereference worker-a's pointer?
The numeric address is interpreted in worker-b's own virtual address space. Explicit IPC or an explicitly shared mapping is needed to transfer or share data.
Does a separate process guarantee the index job survives every thumbnail failure?
No. It isolates the modeled process crash. Shared machine resources, supervisors and external dependencies can still couple failures.
Does releasing process handles undo an already completed write?
No. Resource reclamation closes ownership. Application effects need their own durability, transaction or compensation rules.

Your turn: build the machine, then test its boundaries

Start in Launch & CPU machine. Connect its logical components, launch both photos and follow their mappings and saved contexts. Four construction experiments remove a necessary path or exhaust the modeled RAM. In Communication & crash boundaries, four additional experiments test crash isolation, a foreign address, shared-process failure and when a copy is unnecessary. Each mode states its own model limits.

A program is stored instructions and data. A process is one running instance with an address space, execution state and operating-system-managed resources. Separate processes isolate ordinary memory access and many failures, so communication must cross an explicit boundary.

Open The process workshop. Editable controls require JavaScript; the article and model limits remain readable here.

Sources and model limits

  • Linux proc process status documents observable process state, memory and thread fields.
  • Linux fork, exec and wait distinguish creation, replacement and exit-status collection.
  • Linux file descriptor overview describes the per-process descriptor directory.
  • Linux memory mappings explains file-backed mappings and access permissions; OSTEP execution mechanisms develops context preservation and CPU virtualization.
  • OSTEP process introduction develops the process abstraction and CPU virtualization.
  • The launch/CPU machine models virtual-region ownership, bounded user-page frames and abbreviated saved contexts. Its operations are not real instruction timing; page tables, eviction, swap and OS memory costs are omitted. The communication/crash experiments separately use a declared 16-byte message and injected process fault. Neither machine launches host processes or executes binaries.

Published by GOAT Engineer. Continue with threads and shared process state. Privacy policy · [Contact](mailto:[email protected]).

By GOAT Engineer. Back to Concept Library. Privacy Policy · Contact.