Suppose you inadvertantly spawn enough processes (perl, say) to
exhaust your system’s available PIDs. You know it’s PIDs you’re out of,
not memory, because you had a bunch of memory-hungry processes open too
(Google Chrome helpers, whatever), but you’ve closed them, and still in
a shell you get this:
$ killall -9 perl
[forkpty: Resource temporarily unavailable]
You don’t have a root shell available to get you out
of this mess. Short of rebooting, what to do?
$ exec killall -9 perl
exec corresponds to the execv(2) system call, which handily
replaces your shell with its argument (here, killall -9 perl) rather
than fork(2)ing it into its own process. Keep in mind, however, that
not fork()ing a child process means there’s no parent process to
return to: you get one shot at this trick per shell you have open at the
time.