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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:35:15+00:00 2026-05-13T08:35:15+00:00

I have following problem. I want to create a file system based session storage

  • 0

I have following problem. I want to create a file system based session storage where each session data is stored in simple file named with session ids.

I want following API: write(sid,data,timeout), read(sid,data,timeout), remove(sid)
where sid==file name, Also I want to have some kind of GC that may remove all timed-out sessions.

Quite simple task if you work with single process but absolutly not trivial when working with multiple processes or even over NFS.

The simplest solution I thought about was:

write/read:
   fd=open(file_name,O_CREAT | O_RDWR); // create a new file or use exsting
   fcntl_lock_file(fd)
   save data to fd/read data from fd
   fcntl_unlock_file(fd)
   close(fd)

GC:
   fd=open(file_name,O_RDWR);
   fcntl_lock_file(fd)
   if(timed_out)
      unlink(file_name)
   fcntl_unlock_file(fd)
   close(fd)

The biggest issue that file unlinking works on file names and file locks work on file
descriptors. So the above would not work in following scenario:

GC - open,
write - open
GC - lock, unlink, unlock, close // file still exists because held by write
write - lock, write, unlock, close // file removed

Does anybody have an idea how such issue may be solved? Are there any tricks that allow
combine file locking and file removal or make operation on file atomic?

Notes:

  • I don’t want to use Database,
  • I look for a solution for Unix
  • Solution should work with standard POSIX calls like fcnl, open, close, unlink

Thanks.

Clearification the major issue is that operation on files (names — unlink) should be done atomically with operation of file descriptors — locking:

  • open, unlink — work on files
  • fnctl — work on descriptors
  • 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-13T08:35:15+00:00Added an answer on May 13, 2026 at 8:35 am

    Wouldn’t this work?

    write/read:
       fd=open(file_name,O_CREAT | O_RDWR); // create a new file or use exsting
       fcntl_lock_file(fd)
       if stat(file_name).{st_dev, st_ino} != fstat(fd).{st_dev, st_ino}
           unlock, close, retry
       save data to fd/read data from fd
       fcntl_unlock_file(fd)
       close(fd)
    

    If stat fails with EEXIST (file name does not exist) or shows that the current file is not the same as the one you opened, bail.

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

Sidebar

Ask A Question

Stats

  • Questions 310k
  • Answers 310k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The complete graph on 2 vertices. Denoted K2. See: http://en.wikipedia.org/wiki/Complete_graph May 13, 2026 at 10:05 pm
  • Editorial Team
    Editorial Team added an answer you need to implement this method in the UITableViewDelegate protocol:… May 13, 2026 at 10:05 pm
  • Editorial Team
    Editorial Team added an answer We used to do joins in the application rather than… May 13, 2026 at 10:05 pm

Related Questions

I want to create a resource file for Singaporean English (en-sg) named shopping.en-sg.resx in
I have a filename that has the following format: timestamp-username-1 This file is constantly
I want to create a function which receives a single argument that holds the
I have the following problem using subversion: I'm currently working on the trunk of
I’m trying to create a simple Win32 DLL. As interface between DLL and EXE

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.