#47227 [Opn->Bgs]: children forked with pcntl_fork release flock()s created by parent

From: Date: Wed, 28 Jan 2009 08:44:52 +0000
Subject: #47227 [Opn->Bgs]: children forked with pcntl_fork release flock()s created by parent
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-133255@lists.php.net to get a copy of this message
ID: 47227 Updated by: jani@php.net Reported By: murphyk at yahoo-inc dot com -Status: Open +Status: Bogus Bug Type: PCNTL related Operating System: RHEL 4.4 PHP Version: 5.2.8 New Comment: RTFM: man 2 flock man 2 fork The behaviour is exactly how it should be and is. Previous Comments: ------------------------------------------------------------------------ [2009-01-27 22:07:47] murphyk at yahoo-inc dot com Description: ------------ The behavior of flock()ed files across forks appears to have changed between php 4.4.8 and php 5.2.8. Previously, children would inherit filehandles from their parent, and would close() their copies of the filehandles on exit, but this would not clear flock()s on the files locked in the parent. Now, it appears that if any child exits(), this will clear flock()s on any filehandles inherited from the parent. Reproduce code: --------------- <?php $fp = fopen("/tmp/lock.txt", "w+"); if (flock($fp, LOCK_EX + LOCK_NB )) { print "Got lock.\n"; } else { print "Couldn't lock the file.\n"; exit(); } $pid = pcntl_fork(); if ($pid) { pcntl_waitpid($pid,$status); } else { exit(); } sleep(100); ?> Expected result: ---------------- $ php flock.php & [1] 22054 $ Got lock. $ php flock.php Couldn't lock the file. Actual result: -------------- $php flock.php & [1] 31085 $Got lock. $php flock.php Got lock. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47227&edit=1

« previous php.bugs (#133255) next »