explain_kill(3)

πŸ“¦
version 1.4.D001 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

🌸 explain_kill β€” the manual page, but make it make sense πŸ’…

okay so this is explain_kill(3), a Library Functions Manual page, and bestie it is so useful. it's all about turning those cursed kill(2) errors into actual human words. let's get into it ✨


✨ NAME ✨

explain_kill β€” explain kill(2) errors 🩷


πŸŽ€ SYNOPSIS πŸŽ€

#include <libexplain/kill.h>
const char *explain_kill(pid_t pid, int sig);
const char *explain_errno_kill(int errnum, pid_t pid, int sig);
void explain_message_kill(char *message, int message_size, pid_t pid,
int sig);
void explain_message_errno_kill(char *message, int message_size, int
errnum, pid_t pid, int sig);

πŸ’– DESCRIPTION πŸ’–

these functions? they exist so you can get explanations for errors that the kill(2) system call throws at you. no more staring at a cryptic failure like πŸ‘οΈπŸ‘„πŸ‘οΈ

πŸ¦‹ explain_kill

const char *explain_kill(pid_t pid, int sig);

the explain_kill function grabs you an explanation of an error returned by the kill(2) system call. the least it'll give you is the value of strerror(errno), but honestly? usually it goes way harder and tells you the actual underlying cause in way more detail. iconic behaviour fr fr πŸ’…

the errno global variable is what gets used to obtain the error value to be decoded.

  • pid β€” the original pid, exactly as passed to the kill(2) system call. no edits, no remixes.
  • sig β€” the original sig, exactly as passed to the kill(2) system call. same energy.

Returns: the message explaining the error. ⚠️ this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. it will be overwritten by the next call to any libexplain function that shares this buffer β€” including other threads. so yeah, don't hold onto it like it's yours.

Note: this function is not thread safe, because it shares a return buffer across all threads, and so do many other functions in this library. not me writing multithreaded code with this 😭

Example: this function is meant to be used in a fashion similar to the following example:

if (kill(pid, sig) < 0)
{
    fprintf(stderr, "%s\n", explain_kill(pid, sig));
    exit(EXIT_FAILURE);
}

the above code example is available pre‐packaged as the explain_kill_or_die(3) function. so convenient, we love her 🫢

🌈 explain_errno_kill

const char *explain_errno_kill(int errnum, pid_t pid, int sig);

the explain_errno_kill function gets you an explanation of an error returned by the kill(2) system call. the least the message will contain is the value of strerror(errno), but usually it does much better and points at the underlying cause in more detail. slay ✨

  • errnum β€” the error value to be decoded, usually grabbed from the errno global variable right before this function is called. this is necessary if you need to call any code between the system call you're explaining and this function, because sooo many libc functions will mess with the value of errno. like they will simply alter it. rude.
  • pid β€” the original pid, exactly as passed to the kill(2) system call.
  • sig β€” the original sig, exactly as passed to the kill(2) system call.

Returns: the message explaining the error. ⚠️ this message buffer is shared by all libexplain functions which don't supply a buffer in their argument list. it will be overwritten by the next call to any libexplain function which shares this buffer, including other threads.

Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library too. πŸ’€

Example: this function is intended to be used in a fashion similar to the following example:

if (kill(pid, sig) < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_kill(err, pid, sig));
    exit(EXIT_FAILURE);
}

the above code example is available pre‐packaged as the explain_kill_or_die(3) function. πŸŽ€

🧚 explain_message_kill

void explain_message_kill(char *message, int message_size, pid_t pid,
int sig);

the explain_message_kill function gets you an explanation of an error returned by the kill(2) system call. the least the message will contain is the value of strerror(errno), but usually it does much better and shows the underlying cause in more detail. no cap 🌸

the errno global variable will be used to obtain the error value to be decoded.

  • message β€” the location in which to store the returned message. if you supply a suitable message return buffer, this function is thread safe. okayyy we love a thread-safe moment πŸ‘‘
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • pid β€” the original pid, exactly as passed to the kill(2) system call.
  • sig β€” the original sig, exactly as passed to the kill(2) system call.

Example: this function is intended to be used in a fashion similar to the following example:

if (kill(pid, sig) < 0)
{
    char message[3000];
    explain_message_kill(message, sizeof(message), pid, sig);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre‐packaged as the explain_kill_or_die(3) function. πŸ’œ

πŸ“ explain_message_errno_kill

void explain_message_errno_kill(char *message, int message_size, int
errnum, pid_t pid, int sig);

the explain_message_errno_kill function gets you an explanation of an error returned by the kill(2) system call. the least the message will contain is the value of strerror(errno), but usually it will do much better and indicate the underlying cause in more detail. periodt πŸ’…

  • message β€” the location in which to store the returned message. if a suitable message return buffer is supplied, this function is thread safe. main character energy fr.
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • errnum β€” the error value to be decoded, usually obtained from the errno global variable just before this function is called. this is necessary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. they're always doing the most πŸ™ˆ
  • pid β€” the original pid, exactly as passed to the kill(2) system call.
  • sig β€” the original sig, exactly as passed to the kill(2) system call.

Example: this function is intended to be used in a fashion similar to the following example:

if (kill(pid, sig) < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_kill(message, sizeof(message), err,
    pid, sig);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre‐packaged as the explain_kill_or_die(3) function. ⭐


πŸ”₯ SEE ALSO πŸ”₯


libexplain version 1.4 Copyright (C) 2009 Peter Miller


and that's the whole page bestie πŸ¦‹ go forth and explain your errors, you got this. iykyk πŸ’–

~ with love, from the explain_kill(3) page in the Library Functions Manual ~ 🌈

πŸ“¦ where this page comes from