The POSIX standard
POSIX support
Introduction to APIs
Importance of APIs
Built-in C Standard APIs
Understanding POSIX Standards
POSIX is the acronym for Portable Operating System Interface on Unix-based operating systems. They are IEEE standards to formalize certain common standards in all operating systems in the enterprise market.
In the olden days, programmers struggled to develop an application for computer systems. Before POSIX standards, there were no common standards for developing a computer operating system model, so developers needed to develop their applications for every model—from scratch—to be compatible with all systems. This increased development time and the cost of an application. Debugging was also very difficult because of new bugs and issues in every new computer model, which caused a lot of problems for developers.
POSIX.1
POSIX.1b
POSIX.1c
POSIX.2
POSIX.1 Standards
Process creation and control
Process triggers
Files and directory operations
Segmentation faults
Memory faults
Floating-point exceptions
Pipes
Signals
Standard C library implementation
Standard I/O interface and control
These are some of the core features that the IEEE addressed to improve the interface of all operating systems.
POSIX.1b Standards
CPU scheduling algorithms
Message passing
Shared memory
Semaphore
Memory-locking interfaces
Synchronous and asynchronous data transfer interfaces
All the core features are covered in upcoming chapters.
POSIX.1c Standards
Thread creation
Thread control
Thread deletion
Thread synchronization
Thread scheduling
POSIX.2 Standards
uname
tty
cd
ls
mkdir
echo
cp
rm
mv
This standard list includes all common utilities and the tools that are commonly used by the users.
POSIX Support
All OS models do not use POSIX standards. macOS uses the complete POSIX standards for its operating system, but most Linux distros use the Linux Standard Base (LSB), which includes more powerful features than POSIX. It is a superset of POSIX standards but also independent of POSIX standards. The Windows 10 operating system uses POSIX as a subsystem with the same standard features.
Introduction to APIs
Public API or open API
Private API
Partner API
Composite API
User Mode
In user mode, developers typically develop programs to incorporate or manipulate custom activities in the system. The activities performed at the user level is done with the help of System-level API. The activities include file creation, directory creation, and similar basic activities.
Supervisor Mode
In supervisor mode, system calls perform the actions written by the developers. These built-in functions and libraries are very helpful when it comes to performing system-level tasks. The system call in supervisor mode executes the calls that are made from the user mode. Programs are written to perform some action(s).
The Importance of System-Level APIs
Performance: These libraries are under active development, and developers continuously try to improve the performance of existing functions. Also, they use standard algorithms, such as standard sorting and searching algorithms, to get the best performance.
Reliable code: There are fewer errors because most of the activities are done with built-in functions, and because the libraries are under active development.
Reduces development time: Most of the code is written by developers to perform a particular activity, which reduces development time because there is no need to write code from scratch.
System-independent: C-program compiled binaries are system-dependent, but these built-in libraries are system-independent, which means that they don’t depend on the system. All the built-in functions work the same on all operating systems.
Built-in APIs in C
Most Common Libraries
Library | Functionality |
---|---|
<stdio.h> | This library contains all the standard input and output operation functions: 10 macros and 41 functions. The most popular functions are printf and scanf. |
<stdlib.h> | This is a standard library in C that is mainly used for general-purpose programming. It contains the memory allocation and deallocation functions that perform dynamic activities. |
<unistd.h> | This library provides the standard interface for the POSIX API. |
<sys/types.h> | This library contains standard derived data types, which are helpful in system-level programming. |
<signal.h> | This library handles the signal activities in an operating system. |
<time.h> | This library provides support for time and date activities in a standard manner. |
<sys/stat.h> | This library determines the file system status and activity. |
<fcntl.h> | This library is a part of the POSIX API that manipulates files, such as changing permissions. |
<sys/ipc.h> | This library deals with three major core tasks that include interprocess communication activity (i.e., message queues, semaphores, and shared memory). |
<sys/msg.h> | This library works with the <sys/ipc.h> library to deal with IPC activity. |
<semaphore.h> | This library performs the semaphore activity in an operating system. It is also a part of the POSIX library. |
<sys/shm.h> | This library performs shared memory activities. |
<sys/wait.h> | This library places a process into a waiting state. |
<stdargs.h> | This library handles the variable argument activity that takes input directly from the command-line. |
Summary
This chapter discussed topics related to the POSIX environment and the various C built-in libraries. You were also introduced to system-level APIs.