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 6143207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:29:38+00:00 2026-05-23T18:29:38+00:00

RAII is a good solution for resource cleanup. However, RAII is based on stack

  • 0

RAII is a good solution for resource cleanup. However, RAII is based on stack unwinding. If process terminates abnormally, the stack won’t be unwinded. It means RAII won’t work in this situation. For process life-time’s resource, it’s nothing to worry about, but for file system life tiem or kernal life time resource, such as file, message queue, semaphore, shared memory, it will be a problem.

How can I cleanup the system(fs and kernal) resource in a reliable way?

Example:
A shared file will be create by “master” process, and be used by “slave” process. The shared file should be deleted by “master” process in plan. Does it exist a way to do that.

Obvious, the shared file can’t be unlink at once after it is created. If that, other processes can’t “see” the file.

  • 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-23T18:29:39+00:00Added an answer on May 23, 2026 at 6:29 pm

    There is no perfect answer to your question. You mostly just mitigate the effects as best you can, so that “abnormal termination leaving junk behind” is rare.

    First, write your programs to be as robust as possible against abnormal process termination.

    Second, rely on kernel mechanisms where possible. In your shared file example, if you are just talking about one “master” and one “slave” process using a file to communicate, then you can unlink the file as soon as both processes have it open. The file will continue to exist and be readable and writable by both processes until both of them close it, at which point the kernel will automatically reclaim the storage. (Even if both of them terminate abnormally.)

    And of course, the next time your server starts, it can clean up any junk left by the previous run, assuming only one is supposed to exist at a time.

    The usual last-chance mechanism is to have “cleanup” processes that run periodically to (e.g.) sweep out /tmp.

    But what you are asking is fundamentally hard. Any process responsible for handling another’s abnormal termination might itself terminate abnormally. “Who watches the watchers?”

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

Sidebar

Related Questions

In RAII , resources are not initialized until they are accessed. However, many access
Being primarily a C++ developer the absence of RAII (Resource Acquisition Is Initialization) in
Could you C++ developers please give us a good description of what RAII is,
I've recently posted a general question about RAII at SO . However, I still
RAII = Resource Acquisition is Initialization Ref Counting = poor man's GC Together, they
I've noticed RAII has been getting lots of attention on Stackoverflow, but in my
I have a C++ RAII class for managing Win32 HANDLEs using boost::shared_ptr<> that looks
Since there is no finally in C++ you have to use the RAII design
In practice with C++, what is RAII , what are smart pointers , how
In Visual Studio, I often use objects only for RAII purposes. For example: ScopeGuard

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.