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

  • Home
  • SEARCH
  • 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 470469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:53:16+00:00 2026-05-12T23:53:16+00:00

I am writing a simple app with 24 items in a hash to be

  • 0

I am writing a simple app with 24 items in a hash to be persistent across program executions, so Berkeley DB (DBM) should be well suited for this task.

And it is just for fun.

But I wonder if using it (with Ruby), then when the user presses CTRL-C, then the execution is stopped. In this case, can’t the data be all messed up?

For example, if the value in DB is 63, and I increment it by 1 (to be 64)

63 =  111111 (in binary)  
64 = 1000000 (in binary)

so, could the CTRL-C occur right when the “Most Significant” 1 is written and but the 0s have not been written? In that case, the value in the DB will be 127 instead of 63 or 64. What if it is not Ruby but in C, and the user uses “close window” or “kill” to kill the process? Come to think about it, the hard drive probably write this byte (or 4-byte) to the hard disk surface all at once, so this shouldn’t happen.

if CTRL-C won’t cause this to happen, then a power outage or myself kicking the power plug could cause this to happen? For example, when the value is first cached in RAM, and while it is written to the hard disk, I kick the power plug, and the hard drive loses power before the 0s are written. I know one in a million times, this won’t happen, but this is just a question of curiosity.

On the other hand, if my script is to

  1. Decrement the coin value
  2. Give the user a “hamburger” in his inventory

then when the user presses CTRL-C, and it happens right in between (1) and (2) above, then the user will have less coin, and get no hamburger.

To prevent all these from happening, it’d be to use the transactional method using SleepyCat, SQLite, or MySQL, and none of these will happen?

  • 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-12T23:53:17+00:00Added an answer on May 12, 2026 at 11:53 pm

    No good database system (a category that includes Berkley DB) could be interrupted in the manner you suggest, with a value partially updated. When you press control-c you cannot interrupt the CPU mid-instruction. There is always some level of granularity to the interruption, and well-written databases take advantage of that fact to guard against the database ever being in an inconsistent state.

    The potential for data corruption and loss exists when the power goes out, but the details of whether or not data would be lost or corrupted have more to do with the filesystem on which the database files are stored. A good journaling filesystem, for instance, writes what it is going to do in a “journal” then does it, then writes in the journal that it did it. So if it looses power during a write operation, for instance, it looks at its journal to see if there is anything it needs to finish before allowing access to the filesystem. This is an over-simplification, but you can get the details by checking out ext3 on wikipedia, for example.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This behaviour was chosen because otherwise jQuery would regularly throw… May 13, 2026 at 11:58 am
  • Editorial Team
    Editorial Team added an answer Try setting .SelectedText property or using .Paste(String). May 13, 2026 at 11:58 am
  • Editorial Team
    Editorial Team added an answer Thanks to both responders. The problem turned out to be… May 13, 2026 at 11:58 am

Related Questions

I've really hit a wall and am need of some help! Thankyou for reading
I'm writing an iPhone app that is mainly centered around grid patterns, so I
I'm working with a simple app, that allows user to enter some text, then
I am writing a WPF application that has an optional dependency on an API

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.