
Run Another Program from C with execvp
Run another program from C with execvp on Linux: build argv, search PATH, handle failure, and combine it with fork and waitpid to run a command safely.
Tag
44 posts

Run another program from C with execvp on Linux: build argv, search PATH, handle failure, and combine it with fork and waitpid to run a command safely.

Create a child process in C with fork on Linux, tell parent from child by the return value, and avoid the mistakes that run code twice.

Replace select with poll and struct pollfd to serve many clients in C without the FD_SETSIZE limit, and learn the POLLIN, POLLHUP and POLLNVAL revents.

Build a single-threaded C echo server that serves many clients with select, fd_set, FD_SET and FD_ISSET, and learn why you rebuild the set on every loop.

Check every system call result in C: the -1 convention, short reads and writes, EINTR retries and close errors, with working helpers for Linux and glibc 2.41.

Switch a socket to non-blocking mode with fcntl and O_NONBLOCK, or set it atomically with SOCK_NONBLOCK and accept4, and learn the flag mistakes that bite.

Turn errno into a readable message with perror and strerror in C on Linux with glibc 2.41, and learn when each one fits.

Learn what blocking and non-blocking I/O mean for sockets on POSIX, what EAGAIN tells you, and why servers with many clients switch to non-blocking mode.

errno is a per-thread integer that C library and system calls set on failure. Learn when it is valid and how to read it correctly with glibc 2.41.

Resolve hostnames in C with getaddrinfo, walk the result list, connect to the first address that works, and free it with freeaddrinfo on Linux.

Write a UDP server and client in C with sendto and recvfrom on Linux, and learn why datagrams keep their boundaries but can be lost.

Build a real Unix command-line tool in C from argument parsing to exit codes, pipelines, locale, tests and a man page, with every step explained.