Tag: #posix
How to create an SSH certificate authority
Creating and using an SSH certificate authority, an alternative to the default “trust on first use” model. 2018-03-16
How does reverse DNS lookup work?
Reverse DNS lookup maps an IP address to a domain name by querying
PTR
records. The mapping is not always consistent with the forward DNS lookup. 2018-02-09Don’t use
nscd
nscd
, a local DNS resolver within glibc
, is non-standard. Instead, use a local DNS server like named
or dnscache
. 2018-02-05What does
getaddrinfo
do? getaddrinfo
ostensibly does DNS lookups. Sounds simple, but it uses more than 100 system calls! Let’s trace the crazy path of address lookup on Linux. 2018-02-03How to write a TCP server with the
pthread
API A TCP server that uses
pthread
to serve multiple clients concurrently, with an “echo” server for each connection. 2017-02-28What are the
domain
and type
arguments to the socket
system call? The
domain
and type
arguments to socket()
describe the protocol family and socket type, respectively. The protocol
argument specifies the actual protocol to use, which may be inferred from the domain
and type
. 2017-02-27How to write a TCP server using the
fork
syscall A TCP server that uses the
fork
system call to create a new child process for each accepted connection, allowing it to handle multiple clients concurrently. 2017-02-25What is
mode_t
in C? mode_t
is a bitfield type in C that represents file permissions, including read, write, and execute permissions for the owner, group, and other classes. It provides symbolic constants to set and check these permissions. 2017-02-24What is
ssize_t
in C? ssize_t
is a signed version of size_t
, used to represent return values from system calls that may need to indicate error with -1
. 2017-02-22What is a a FIFO, or “named pipe”? What is
mkfifo
in C? A FIFO is a special file that allows inter-process communication. The
mkfifo
system call creates a FIFO, enabling processes to read from and write to it. 2017-02-21What is
lsof
? lsof
lists open system resources, including pipes, sockets, and yes, files. It shows their type, owner, and location. 2017-02-20How do I call a program in C, setting up standard pipes?
A C function to create a new process, set up its standard input/output/error pipes, and return a struct containing the process ID and pipe file descriptors. 2017-02-17
How do I close a file descriptor in C?
To close a file descriptor in C, use the
close
system call. Multiple descriptors can reference the same underlying file or pipe. The pipe is only closed when all references are closed. 2017-02-16How do I duplicate a file descriptor in C?
Use the
dup
system call to duplicate a file descriptor in C, allowing two references to the same underlying pipe. 2017-02-15UNIX as a SQL database
UNIX represents various system components, like processes, file descriptors, and memory, using in-memory data structures that can be modeled as relational database tables. 2017-02-14
How do I call a program from C?
To call a program from C, use `fork` then `execve`. There is no more direct way! 2017-02-07
How do I use
fork
in C? fork
duplicates the current process. It returns 0
in the child process. In the parent process, it returns the child’s new process id. 2017-02-06How do I use
execve
in C? execve
replaces the current process with a new one. It takes a path, an argument array, and an environment array. The process never returns unless execve
fails. 2017-02-05How do I access environment variables in C?
Access environment variables in C by using the global
environ
variable, which points to an array of string pointers representing the environment. 2017-02-02What system calls does macOS have?
All system calls on macOS 10.12, categorized by the functionality they provide, such as process management, file operations, memory management, etc. 2017-01-31
How do I read
man
pages? The
man
command is used to access the UNIX manual pages, which are organized into numbered sections. man
searches a predefined path to find the relevant manual page. 2017-01-30In what ways can processes communicate?
Processes can communicate via files, pipes, signals, sockets, message queues, semaphores, and shared memory. 2017-01-29
What syscalls does a UDP server need?
The syscalls needed for a simple UDP echo server are
socket
, bind
, recvfrom
, sendto
, and close
. 2016-12-19How to write a TCP server with the
kqueue
API Kqueue is a more efficient alternative to
select
for managing multiple TCP connections, providing a publish-subscribe model for tracking events in the kernel. 2016-12-18How to write a TCP server with the
select
syscall The
select
syscall allows a process to sleep and wake up when a file descriptor is ready for reading, writing, or has an exceptional condition. This enables a TCP server to handle multiple clients concurrently. 2016-12-16What is a “file descriptor”, really?
File descriptors should be called “resource descriptors”. They represent various system resources, not just regular files. The operations you can perform depend on the specific resource. 2016-12-15
What syscalls does a TCP server need?
A minimal TCP server in C uses the
socket
, bind
, listen
, accept
, recv
, send
, and close
syscalls to manage connections. 2016-12-14All content copyright James Fisher.