php無法產生類似.pid的標識進程的臨時檔案

來源:互聯網
上載者:User
    在linux C編程裡,大家都知道在一個進程裡建立一個檔案,保持開啟狀態,然後unlink掉檔案,它並不實際刪除,而是等到進程結束時,所有的fd都關閉了,才真正清除掉。     在php裡,用同樣的操作方法想得到一個標識一個進程尚在啟動並執行pid檔案,未果!    在php裡,如果建立一個檔案,並保留此檔案的引用指標,則無法unlink檔案,會報錯:Warning:  unlink Permiss denied。如果不保留檔案指標或將其unset掉,則檔案立即刪除了,而不是等到進程結束。也就是,同C編程相比,php不允許刪除尚有引用指標的檔案。     下面是php和C的代碼:php: 

<?php
$filename = "/tmp/test_php.pid";
$fp = fopen($filename, 'w');
//unset($fp);
unlink($filename);
sleep(6);

C:

#include <stdio.h>

int main()
{
    char *filename = "/tmp/test_c.pid";
    FILE *fp;
    fp = fopen(filename, "w");
    unlink(filename);
    sleep(6);
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.