KILLPG(2)

πŸ’– KILLPG(2) πŸ’–

ok so bestie, welcome to the System Calls Manual ✨ we're talking about killpg today and honestly? it's giving group-chat energy but for processes. no cap.


🌸 NAME 🌸

killpg β€” send signal to a process group πŸ’…

πŸ“š LIBRARY πŸ“š

Standard C Library (libc, -lc) 🫢

✨ SYNOPSIS ✨

#include <sys/types.h>
#include <signal.h>

int
killpg(pid_t pgrp, int sig);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the killpg() function sends the signal sig to the process group pgrp. that's it, that's the whole vibe. it's the "hey everyone in this group, listen up" of system calls πŸ”₯

if you wanna know what signals even are, go peek at sigaction(2) for the full list β€” it's a whole menu, pick your fighter.

and here's the cute part: if pgrp is 0, then killpg() sends the signal to the sending process's own process group. it's like texting your own group chat. main character behavior tbh πŸ’€

⚠️ bestie, listen: the sending process must be able to kill() at least one process in the receiving process group. you can't just barge in. the rules are the rules, periodt.

πŸŽ€ RETURN VALUES πŸŽ€

killpg() returns the value 0 if successful 😌 slay. otherwise, the value -1 is returned and the global variable errno is set to indicate the error 😭 (yes we're checking errno, always check errno).

πŸ’€ ERRORS πŸ’€

the killpg() function will fail and no signal will be sent if any of these happen:

  • [EINVAL] β€” the sig argument is not a valid signal number πŸ™ˆ like girl what number is that
  • [ESRCH] β€” no process can be found in the process group specified by pgrp πŸ‘» it's empty in there, nobody home
  • [EPERM] β€” kill() returns EPERM for all processes in the process group 🚫 you don't have the permissions, respectfully denied

🌈 SEE ALSO 🌈

iykyk, go read those next 🧚

⭐ HISTORY ⭐

the killpg() function appeared in 4.0BSD. old money, iconic, legendary behavior πŸ‘‘


and that's the whole page, bestie πŸ’– this one's from the Debian fam, dated March 15, 2012, and it lives in KILLPG(2). go forth and signal your process groups responsibly 🫢🌸✨

πŸ“¦ where this page comes from