What is POSIX?
- C course
- Advanced
- Lesson 1/83
- 5 min
Learn the POSIX standard and its relation to C.
What is POSIX?
POSIX (Portable Operating System Interface) is a standard defined by IEEE that specifies a common interface for UNIX-like systems. When you do systems programming in C, you use POSIX functions.
POSIX defines low-level APIs such as file operations (open, read, write), process management (fork, exec) and sockets. Its header is <unistd.h>. Linux, macOS and BSD systems are POSIX compliant.
Why POSIX?
With POSIX, you can compile and run the same C code on Linux, macOS and BSD without changes. The standard C library (stdio.h) provides high-level I/O, while POSIX provides low-level I/O.
For example, fopen opens a file with a FILE structure; open returns a file descriptor. Descriptors are faster and more controllable: with read and write you work directly at the byte level. In this lesson you will see the core POSIX concepts.
Practice Print signal names
Use printf to print three POSIX signal names, one per line: SIGINT, SIGTERM and SIGKILL. End each line with \n.
Starter code
#include <stdio.h>
#include <signal.h>
// Print SIGINT
// Print SIGTERM
// Print SIGKILL
int main(void) {
return 0;
}Sample solution
#include <stdio.h>
#include <signal.h>
int main(void) {
printf("SIGINT\n");
printf("SIGTERM\n");
printf("SIGKILL\n");
return 0;
}Expected output
SIGINT SIGTERM SIGKILL
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does POSIX stand for?
- Portable Operating System Interface Correct answer
- Portable Operating System Internal
- Process Oriented System Interface
- Parallel Operating System Interface
Explanation: POSIX stands for Portable Operating System Interface.
2 POSIX header file
#include <____.h>
#include <stdio.h>
#include <unistd.h>
#include <stdio.h>
Explanation: unistd.h is the core POSIX header.
3 Match the POSIX concepts
| Term | Meaning |
|---|---|
POSIX |
Portable interface |
unistd.h |
POSIX header |
fcntl.h |
File control |
sys/types.h |
Type definitions |