Linux Programming Interface Cheat Sheet
Introduction
This cheat sheet provides a comprehensive list of commonly used functions in the Linux programming interface. These functions are essential for interacting with the operating system, managing processes, files, memory, network communication, and performing various system-related tasks.
Table of contents
- Introduction
- Process Control Functions
- File and I/O Functions
- Memory Management Functions
- Process Scheduling Functions
- Signal Handling Functions
- Interprocess Communication Functions
- File System Functions
- Network Programming Functions
Process Control Functions
fork()
: Create a new process by duplicating the existing process.exec()
family: Replace the current process image with a new program.wait()
andwaitpid()
: Suspend the calling process until one of its child processes exits.exit()
: Terminate the calling process and return the exit status.getpid()
: Get the process ID of the calling process.getppid()
: Get the parent process ID of the calling process.signal()
: Set a signal handler for a specific signal.kill()
: Send a signal to a process or a group of processes.nice()
: Modify the priority of a process.
File and I/O Functions
open()
: Open a file or create one if it does not exist.read()
andwrite()
: Read from or write to a file descriptor.close()
: Close a file descriptor.lseek()
: Change the file offset within a file.dup()
anddup2()
: Duplicate a file descriptor.pipe()
: Create a pipe for interprocess communication.fopen()
,fclose()
,fread()
, andfwrite()
: File operations usingFILE
streams.fgets()
,fputs()
, andfprintf()
: Read from or write to aFILE
stream.stat()
,fstat()
, andlstat()
: Retrieve file status information.mkdir()
: Create a new directory.rmdir()
: Remove an empty directory.chdir()
: Change the current working directory.
Memory Management Functions
malloc()
,calloc()
,realloc()
, andfree()
: Dynamic memory allocation and deallocation.mmap()
,munmap()
, andmsync()
: Map files or devices into memory.brk()
andsbrk()
: Change the program break, modifying the heap’s memory space.
Process Scheduling Functions
sleep()
: Suspend the execution of the calling process for a specified number of seconds.usleep()
: Suspend the execution of the calling process for a specified number of microseconds.sched_yield()
: Yield the processor to another thread or process.setpriority()
: Set the scheduling priority of a process.nice()
: Modify the priority of a process.
Signal Handling Functions
signal()
: Set a signal handler for a specific signal.sigaction()
: Set a signal handler with extended capabilities.kill()
: Send a signal to a process or a group of processes.sigprocmask()
: Change the signal mask for the calling process.
Interprocess Communication Functions
pipe()
: Create a pipe for communication between two related processes.shmget()
,shmat()
, andshmdt()
: Create or attach to a shared memory segment.msgget()
,msgsnd()
, andmsgrcv()
: Create or send/receive messages to/from a message queue.semget()
,semop()
, andsemctl()
: Create or operate on a semaphore.socket()
: Create an endpoint for communication.bind()
: Assign a local address to a socket.- `
listen()`: Mark a socket as a passive socket, ready to accept connections.
accept()
: Accept a connection on a socket.connect()
: Establish a connection to a remote host.send()
andrecv()
: Send or receive data on a socket.getaddrinfo()
andfreeaddrinfo()
: Convert hostnames and service names to socket addresses.
File System Functions
opendir()
,readdir()
, andclosedir()
: Open, read, and close a directory.scandir()
: Scan a directory for files matching a specific criterion.chown()
: Change the owner and group of a file.chmod()
: Change the permissions of a file.rename()
: Rename a file.remove()
: Delete a file.link()
andunlink()
: Create or remove a hard link to a file.symlink()
andreadlink()
: Create or read the value of a symbolic link.utime()
: Change the access and modification times of a file.realpath()
: Resolve the absolute path of a file.
Network Programming Functions
gethostbyname()
andgethostbyaddr()
: Retrieve host information by name or address.getaddrinfo()
andfreeaddrinfo()
: Convert hostnames and service names to socket addresses.socket()
: Create an endpoint for communication.bind()
: Assign a local address to a socket.listen()
: Mark a socket as a passive socket, ready to accept connections.accept()
: Accept a connection on a socket.connect()
: Establish a connection to a remote host.send()
andrecv()
: Send or receive data on a socket.select()
: Monitor multiple file descriptors for readiness.setsockopt()
andgetsockopt()
: Set or retrieve options on a socket.
These are just some of the many functions available in the Linux programming interface. Each function provides specific functionality for interacting with different aspects of the operating system and building robust Linux applications.
Please refer to the relevant man pages and official documentation for detailed usage and additional functions available in the Linux programming interface.