Processes and Threads
The material on this Page is meant to be a brief review of some operating system terminology. Although the details are presented in the context of the Unix operating system, it is really the underlying functionality captured by these terms that is important for this course. This functionality is more or less present in most familiar operating systems.
A Unix Process consists of:
- A unique Process ID.
- The current context - state of execution, (next instruction to be executed, if waiting etc.)
- Open files
- Permissions (UID GID)
- Present Working Directory.
- Allocated Memory
The process is the basic scheduling unit for the operating system.
A Unix Thread (of execution) can be thought of as a member of collection of instances of a single program running in multiple places at the same time:
- Having a common PID
- Having different "contexts."
- Sharing open files.
- Sharing Permissions
- Having the same Present Working Directory.
- Having the same memory image.
- Having a common set of Global Variables
The differences between Processes and Threads are reflected in the system calls:
Communications
Sockets :
Socket protocols provide for a bidirectional flow of data
between processes
that may or may not live on the same host.
Once sockets have be created and the connections between processes have been established, using sockets have the same characteristics as reading an writing to files. The following provides a bit more detail:
On the server side:
- Create a socket with socket().
- bind() the socket to an address (IP address and port number).
- listen() for a connection.
- accept() a connection.
- Send and receive data For example, use read() and write() .
On the client
side:
- Create a socket with socket().
- Connect the socket to the address of the server using connect().
- Send and receive data.
Shared Memory:
As the phrase suggests, shared memory a common region of memory (address space) where the sharing processes or threads may all read or write. This can be a particularly efficient means of Inter Process Communications since it does not require any operating system overhead. On the other hand it does require some form of synchronization between the processes or threads to guaranty the integrity of the data in the shared memory region.