POSIX
POSIX
TIME SYSTEMS
1
Example of Real Time
Operating Systems
2
Example of RTOS
POSIX
Windows CE
3
POSIX
POSIX - Portable Operating System Interface
POSIX.1 – Core services
POSIX.1b – Real-time extensions
POSIX.1c – Thread extensions
The POSIX standard is written in terms of the C
programming language. POSIX supports two
programming environments.
One is based on the Traditional C language.
The other is based on the Standard C language
defined by American National Standard for Information
Systems.
Since Standard C was developed by the American
National Standards Institute (ANSI), some people call
it ANSI C
4
POSIX is based on UNIX operating system.
Usually UNIX was not originally designed as a real
time operating system, POSIX has been extended to
support real time requirements.
POSIX defines a standard way for an application to
interface to the operating system.
The original POSIX standard defines interfaces to
core functions such as file operations, process
management, signals, and devices.
5
POSIX
6
The POSIX process model
• POSIX does not implement lightweight
processes.
7
Processes in POSIX
In POSIX, a new process is created by making a copy
of an existing process
8
A process makes a copy of itself by calling fork()
function
It creates a new child process which is exact copy
of parent process
The both have the same code and the same data
values with one exceptions the return value of fork()
– Parent Process: returns the process ID of the
child process
– Child process: returns 0
We can Test the return value of fork() to determine
which process is the child.
9
execv() function –> It takes the list of arguments to
the process in the form of array.
perror() & exit() function –> To perform call
functions.
parent_stuff() function –> To perform the work of
parent function.
wait() function –> It make wait the child process
10
Real time scheduling in POSIX
• POSIX supports real time scheduling in the
_POSIX_PRIORITY_SCHEDULING resource
• The sched_setscheduler() function is used to determine a
process’s scheduling policy and other parameters
Ex: i = sched_setscheduler (process_id, SCHED_FIFO,
&sched_params)
It tells POSIX to use the SCHED_FIFO policy for this process
along with some other scheduling parameters.
sched_getparams() function returns the current parameter values
for a process
sched_setparams() function changes the parameter values
11
SCHED_FIFO scheduling
12
SCHED_RR
• SCHED_RR is a combination of real-time and
interactive scheduling techniques:
• within a priority level, the processes are timesliced.
Interactive systems must ensure
• that all processes get a chance to run, so time is
divided into quanta. Processes get the
• CPU in multiple of quanta
13
SCHED_OTHER
• The SCHED_OTHER is defined to allow non-real-
time processes to intermix with realtime processes.
• The precise scheduling mechanism used by this
policy is not defined.
• It is used to indicate that the process does not need a
real-time scheduling policy.
14
POSIX
• POSIX supports
Semaphores
Message Queues
15
POSIX semaphores
POSIX supports Counting semaphores in the
_POSIX_SEMAPHORES option
16
semaphores
• At that point, the blocked process can resume only
after one of the processes has given up its semaphore.
• The simplest way to think about counting semaphores
is that they count down to 0- when the semaphore
value is 0-,
• the process must wait until another process gives
up the semaphore and increments the count.
17
POSIX semaphores
18
POSIX Shared Memory
POSIX shared memory is supported under the
_POSIX_SHARED_MEMORY_OBJECTS option.
Shared memory functions create blocks of memory
that can be used by several processes
• shm_open() – To open a shared memory
• objdesc = shm_open(“/memobj1”,O_RDWR);
19
• Before using the shared memory object, we must
map it into the process memory
• space using the mmap() function. POSIX assumes
that shared memory objects
• fundamentally reside in a backing store such as a disk
and are then mapped into the address space of the
process.
20
POSIX pipes
• The pipe is very familiar to Unix users from its shell syntax:
21
• Each end of a pipe appears to the programs as a filed
the process at the head of the pipe writes to one file
descriptor while the tail process reads from another
file descriptor.
• The pipe() function returns an array of file
descriptors,
• The first for the write end and the second for the read
end.
22
POSIX Message Queues
POSIX supports message queues under the
_POSIX_MESSAGE_PASSING option.
Message queues starts with “/”
No need to create a queue before creating a process
24