Ignore SIGPIPE process-wide with signal(SIGPIPE, SIG_IGN)
Writing to a closed pipe or socket kills the process with SIGPIPE. Ignore the signal and write(2) returns -1 with EPIPE, which you can handle in the code.
Short posts that solve one thing: the code, the output we got, and why it works.
Writing to a closed pipe or socket kills the process with SIGPIPE. Ignore the signal and write(2) returns -1 with EPIPE, which you can handle in the code.
malloc(3) returns NULL and sets ENOMEM when it cannot allocate. Test it before use, and know that Linux overcommit often kills the process instead of failing.
Read the memory page size at run time with sysconf(_SC_PAGESIZE) instead of hard-coding 4096, which is wrong on arm64 kernels built with 16K or 64K pages.
Turn one show function into a complete read-only debugfs file with DEFINE_SHOW_ATTRIBUTE() in Linux 6.12, with no hand-written file_operations.
Detach a daemon from its terminal by forking, exiting the parent and calling setsid in the child on Linux 6.12, so closing the terminal cannot hang it up.
Make GCC 14 check the arguments of your own printf-style logger with __attribute__((format(printf, 1, 2))), the same way it checks printf.
SYSCALL_DEFINE2() declares a system call with two arguments, builds its wrapper, and needs one line in the syscall table (Linux 6.12, x86-64).
Cap the CPU time a process may use with setrlimit and RLIMIT_CPU on Linux 6.12, catch the SIGXCPU warning at the soft limit, and know when SIGKILL follows.
Look up the account name of the effective user in C with geteuid and getpwuid_r on Linux with glibc 2.41, without trusting the USER variable or getlogin.
Read the current Unix epoch seconds with time(NULL) on glibc 2.41, and build 32-bit targets with _TIME_BITS=64 so time_t survives the year 2038.
Print the exact directories GCC 14 searches for headers by preprocessing empty input with gcc -xc -E -v -, with no source file needed.
getenv returns NULL for an unset variable and an empty string for a set-but-empty one, so test both before falling back to a default.
We send one email when a new post is published. No spam.