Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101654 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3412 invoked from network); 22 Jan 2018 15:58:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Jan 2018 15:58:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=thruska@cubiclesoft.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=thruska@cubiclesoft.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain cubiclesoft.com designates 149.56.142.28 as permitted sender) X-PHP-List-Original-Sender: thruska@cubiclesoft.com X-Host-Fingerprint: 149.56.142.28 28.ip-149-56-142.net Received: from [149.56.142.28] ([149.56.142.28:60570] helo=28.ip-149-56-142.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B1/B7-28995-D0A066A5 for ; Mon, 22 Jan 2018 10:58:10 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: thruska@cubiclesoft.com) with ESMTPSA id B43293E8C4 To: David Rodrigues , PHP Internals References: Message-ID: <630ac0e1-692b-ae0b-54f3-94da6f9df7d9@cubiclesoft.com> Date: Mon, 22 Jan 2018 08:58:00 -0700 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] PCNTL compatibility to Windows? From: thruska@cubiclesoft.com (Thomas Hruska) On 1/22/2018 5:16 AM, David Rodrigues wrote: > Hello. > > I know that PCNTL extension is not compatible with Windows, but I can't > found the reason for that. > > I mean, I know that it is a feature that Unix system could provide in a > better way (natively I guess). But "why" Windows could not emulates this > features and have a PCNTL support too? Even if it had a lower performance, > it still could be useful on testing environments. > > So the question is: there are some hard limitation to it be impossible or > would it be kind of a "lack of interest"? > > Thanks! Windows is a completely different OS. Windows does not have signals: https://stackoverflow.com/questions/3333276/signal-handling-on-windows That rules out all of PCNTL's signal handling support, which is 11 out of the 22 functions that PCNTL has (I'm excluding aliases in that count). Simply being unable to implement 50% of the functions is not a good start to a successful port. Windows does not have fork/exec. Although there are non-starter "solutions": https://en.wikipedia.org/wiki/Fork%E2%80%93exec Windows starts and manages processes VERY differently from *NIX. Cygwin apparently has a working fork/exec implementation for Windows, but Cygwin is GPL. Any implementation would have to be clean-roomed for PHP and would likely involve ugly things such as copying raw memory from one process space to another and/or using undocumented Zw kernel calls, all of which can change dramatically between OS releases. Windows processes are referenced by HANDLE, not process ID. Referencing by process ID might seem doable with OpenProcess(): https://msdn.microsoft.com/en-us/library/windows/desktop/ms684320(v=vs.85).aspx But even PROCESS_QUERY_LIMITED_INFORMATION access might be denied when attempting to open the handle. Even for child processes. It happens when a process changes its own DACLs specifically to block OpenProcess()/OpenThread() calls. Although the approach can't readily block SeDebugPrivilege, you don't ever want PHP core/userland running with SeDebugPrivilege. A PHP implementation might work fine for direct children for most use-cases where the HANDLEs are kept around, but grandchildren might not be accessible. Also, there's already the "proc_..." series of functions for handling child processes, which more correctly uses generic resource handles instead of integers. Windows does not know what a zombie process is. Unlike *NIX, Windows doesn't have a rule that a child must have a parent and that the parent must wait on each child to exit before the parent itself exits. Windows processes can exit whenever they want and the kernel cleans up after the process. Windows does have a few process priorities: https://msdn.microsoft.com/en-us/library/windows/desktop/ms686219(v=vs.85).aspx However, you can do things such as completely freeze up Windows - including the keyboard processing buffer and mouse cursor - with a process priority of REALTIME_PRIORITY_CLASS and a "while (1)" loop where the specified process will get *exclusive* scheduling by the kernel (i.e. a reboot is the only option). It's a little-known security vulnerability-waiting-to-happen bit of Windows API history. I dunno. When all is said and done, pcntl_getpriority(), pcntl_setpriority(), pcntl_get_last_error(), pcntl_strerror(), and maybe pcntl_wait() and associated status functions are about the only functions that can be somewhat cleanly implemented for Windows using Windows APIs with minimal effort. pcntl_waitpid() might be able to be implemented with some effort but possibly not work properly for pids less than 1 (with all the usual waitpid() caveats). The signal handling are simply not doable. Implementing fork/exec doesn't make a lot of sense - a lot of effort for little gain. -- Thomas Hruska CubicleSoft President I've got great, time saving software that you will find useful. http://cubiclesoft.com/ And once you find my software useful: http://cubiclesoft.com/donate/