PHP cannot generate a temporary file similar to. PID identification process

Source: Internet
Author: User
In Linux C Programming, everyone knows to create a file in a process, keep it open, and unlink the file. It does not actually delete it, but waits until the process ends, all FD are disabled before they are actually cleared. In PHP, the same operation method is used to get a PID file that identifies a process that is still running! In PHP, if a file is created and the reference pointer of the file is retained, the unlink file cannot be created, and the following error occurs: Warning: unlink permiss denied. If the file pointer is not retained or unset, the file is deleted immediately, instead of waiting until the process ends. That is, PHP does not allow you to delete objects that still reference pointers compared with C programming. The following is the PHP and C code: 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);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.