Chapter 5. RHEL for Real Time processes and threads

The RHEL for Real Time key factors in operating systems are minimal interrupt latency and minimal thread switching latency. Although all programs use threads and processes, RHEL for Real Time handles them in a different way compared to the standard Red Hat Enterprise Linux.

In real-time, using parallelism helps achieve greater efficiency in task execution and latency. Parallelism is when multiple tasks or several sub-tasks run at the same time using the multi-core infrastructure of CPU.

5.1. Processes

A real-time process, in simplest terms, is a program in execution. The term process refers to an independent address space, potentially containing multiple threads. When the concept of more than one process running inside one address space was developed, Linux turned to a process structure that shares an address space with another process. This works well, as long as the process data structure is small.

A UNIX®-style process construct contains:

  • Address mappings for virtual memory.
  • An execution context (PC, stack, registers).
  • State and accounting information.

In real-time, each process starts with a single thread, often called the parent thread. You can create additional threads from parent threads using the fork() system calls. fork() creates a new child process which is identical to the parent process except for the new process identifier. The child process runs independent of the creating process. The parent and child processes can be executed simultaneously. The difference between the fork() and exec() system calls is that, fork() starts a new process which is the copy of the parent process and exec() replaces the current process image with the new one.

In real-time, the fork() system call, when successful, returns the process identifier of the child process and the parent process returns a non-zero value. On error, it returns an error number.

5.2. Threads

In real-time, multiple threads can exist within a process. All threads of a process share its virtual address space and system resources. A thread is a schedulable entity that contains:

  • A program counter (PC).
  • A register context.
  • A stack pointer.

In real-time, following are potential mechanisms to create parallelism:

  • Using the fork() and exec() function calls to create new processes. The fork() call creates an exact duplicate of a process from which it is called and has a unique process identifier.
  • Using the Posix threads (pthreads) API to create new threads within an already running process.

You must evaluate the component interaction level before forking real-time threads. Creating a new address space and running it as a new process is beneficial when the components are independent of one another or with less interaction. When components are required to share data or communicate frequently, running the threads within one address space is more efficient.

In real-time, the fork() system call, when successful, returns a zero value. On error, it returns an error number.

5.3. Additional resources

  • fork(2) man page
  • exec(2) man page