posix_kill vs pcntl_signal
Asked Answered
V

1

6

This is a bit esoteric and it's possible this question will go unanswered until I troll the the source myself and answer it, but here goes:

I'm the author of a simple PHP Daemon library: https://github.com/shaneharter/PHP-Daemon. While PHP isn't ideal for this sort of thing, sometimes people need to daemonize or write crons in PHP and wrote the library to make that task a lot easier on the "uninitiated."

I'm implementing the JavaScript Workers API for the library and I'm considering adding a dependency on POSIX (right now it's doing everything with PCNTL).

Does anybody know what the difference is between PCNTL_SIGNAL and POSIX_KILL? I can use either to send any signal to any process. So.... is one better than the other? Or are they both really doing the same thing under the hood?

Velours answered 30/8, 2011 at 19:29 Comment(2)
Nice project. Good luck!Fulvous
They're actually very different. One listens to signals, and the other sends signals.Hollingsworth
N
11

posix_kill() is used to send a signal to a process.

pcntl_signal() is used to listen for signals received by the calling process (your script).

See the examples here.

Nature answered 30/8, 2011 at 19:31 Comment(1)
Haha, wow. Great reality check. How did I get that in my head? It's one of those things -- 5 second glance at the docs (or my own code written 10 months ago) would've dispelled. A few weeks ago I was looking over the docs on PHP Semaphores, SEM, libevent, posix, etc, and I thought "Huh, why does POSIX extension implement a way to send signals, PCNTL has the same thing" -- And after that, it just became my own conventional wisdom. Anyway, thanks for taking a min to answer. Despite the ignorance of my question -- check out that daemon library if you ever have the need. It's really coming along!Velours

© 2022 - 2024 — McMap. All rights reserved.