linux下remove删除函数删除文件,文件存在,调用后返回为0,文件却没有删除,求解?
发布网友
发布时间:2022-04-24 11:33
我来回答
共2个回答
热心网友
时间:2023-10-11 07:59
如果文件正在被使用的话,文件的真正删除是在你解除引用之后进行,但是不需要用户进行操作来干预了,文件一定会删除.
如果你想调用remove之后马上看到文件被删除,建议你判断是否被占用。或者使用system("rm -rf filename").
热心网友
时间:2023-10-11 08:00
DESCRIPTION
remove() deletes a name from the file system. It calls unlink(2) for files, and rmdir(2) for directories.
If the removed name was the last link to a file and no processes have the file open, the file is deleted and the space it was using is made available for reuse.
/*----------------------------------------------------------------------------*/
If the name was the last link to a file, but any processes still have the file open, the file will remain in existence until the last file descriptor referring to it is closed.
/*----------------------------------------------------------------------------*/
If the name referred to a symbolic link, the link is removed.
If the name referred to a socket, FIFO, or device, the name is removed, but processes which have the object open may continue to
use it.
RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
函数描述是成功返回0,失败返回-1;不知道你是怎样写的程序,可不可以挂出来看一下;