Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6901555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:41:18+00:00 2026-05-27T07:41:18+00:00

code: int main(int argc, char **argv) { int fd = open(test.txt, O_CREAT|O_RDWR, 0200|0400); if(fd

  • 0

code:

int main(int argc, char **argv)
{
    int fd = open("test.txt", O_CREAT|O_RDWR, 0200|0400);
    if(fd == -1)
    {
        printf("failure to oepn");
        exit(-1);
    }
    int iRet = write(fd, "aaaaaaaaaa", 10);

    if(iRet == -1)
    {
        printf("failure to writer");
        exit(-1);
    }
    sleep(10);
    printf("You must remove");
    iRet = write(fd, "bbbbbbbbbb", 10);

    if(iRet == -1)
    {
        printf("failure to after writer");
        exit(-1);
    }

   exit(0);
}

during the sleep(), you delete the test.txt, but the process write successful!why?
if a log ”Singleton“ instance, you remove the file on the disk.write is successful, but you can get nothing.

class log
{
public:
    void loggerWriter(std::string str);
    int fd;
};

log::log(std::string filename):fd(-1)
{
    fd = open(filename.c_str(), O_CREAT|)
    //...
}

log::loggerWriter(std::string str)
{
    writer(fd, str.c_str(), str.size());
}

int main()
{
    log logger("text.txt");
    //...
    //I want to know the text.txt the text.txt have delete on the disk or not.
    //if delete i can create another file to log. 
}

“unlink” cann’t solve this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:41:19+00:00Added an answer on May 27, 2026 at 7:41 am

    The manual page for unlink(2) states clearly:

    unlink() deletes a name from the file system. If that 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
    .

    As caf excellently notes in the comments:

    The write() is successful because it writes to the file, which still
    exists at this point even though it no longer has a name. The filename
    and the file itself are distinct, and have separate lifetimes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: int main(int argc, char** argv) { onelog a; std::cout
Following simplified code snippet: #include <QtGui> int main(int argc, char **argv) { QApplication app(argc,
The code #include <QtCore> #include <QtXml/QDomElement> int main(int argc, char *argv[]) { QCoreApplication app(argc,
The following code compiles fine ... int main (int argc, const char * argv[])
I have written a source code like: int main(int argc, char *argv[]) { QFile
Using the following code to write to a file int main(int argc, char *
#include <stdio.h> #include <stdlib.h> #include <string.h> int main ( int argc, char *argv[] )
I got an EXC_BAD_ACCESS in main() , here is my code: int main(int argc,
The code is simple enough: #include <iostream> #include <fstream> #include <string> int main(int argc,
Example code : int main() { std::vector<int> v1{1, 2, 3, 4, 5, 6, 7,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.