back up data in C how & when in sudden poweroff?????????

S

skishorev

Hi,

In sudden power off, How to backup means in which format(files,
streams) & when to backup in C.

Thanks,
SAI
 
W

Walter Roberson

In sudden power off, How to backup means in which format(files,
streams) & when to backup in C.

Unfortunately I don't understand your question, and the parts
of it that I think I understand would suggest that it isn't
really on topic for this newsgroup. Could you perhaps
expand on what you are trying to back up?

Are you asking how to save state information in a C program
so that you can restart the program at close to the same place
if you need to? And are you asking in particular how to save
state information about open files and streams? Or are you
asking whether you should save *to* a file or to a stream?
 
S

skishorev

Hello Roberson,

If i want to save the state information incaseof sudden power down,
which one is the better? Is it in File or in stream.

How do save to a file or to a stream?
 
S

skishorev

Hello Roberson,

If i want to save the state information incase of sudden power down,
which one is the better? Is it in File or in stream.


How do save to a file or to a stream?

Thanks ,
SAI.....
 
W

Walter Roberson

Hello Roberson,

"Roberson" is my family name; "Walter" is my given name.

If i want to save the state information incaseof sudden power down,
which one is the better? Is it in File or in stream.

As far as the C language itself is concerned, streams are the
only things that exist.

In standard C, you start out with three predefined streams (stdin,
stdout, and stderr) and you can [try to] create additional streams by
using fopen().

The name you pass to fopen() is interpreted by the operating
system, which might happen to consider it to be the name of a file,
but might happen to consider it to be the name of something else
(such as a device or network connection. The C language itself
(and the routines in the standard C library) do not provide any
way to find out what kind of object was accessed: all your
program knows about it is that a stream was provided to access
whatever the underlying object really is.

Accordingly, in standard C, the question of whether to save to
a file or a stream is not very meaningful.

If you go outside of the C standard, your operating system
may provide additional routines to access specific kinds of
objects, or may make additional guarantees about what names
will correspond to what kind of objects: anything like that is
an extension to C, and the details of the extensions need to be
explored in a newsgroup more specific to your operating system.


*Generally* speaking, if you are in emergency powerfail operations,
then you do not have time to wait for a network connection to
be created (as that could take several minutes or might not
be available at all), so you usually want to save information to
something local. You probably want to save a minimal amount of
information as soon as possible, and possibly expand upon that if
you manage to get some spare time. You want the saved information
to be left in a consistant state, so you want to avoid having
a file open and being written to when the computer and operating
system run out of grace time, so your strategy might involve
several files.
 
G

Gordon Burditt

If i want to save the state information incase of sudden power down,
which one is the better? Is it in File or in stream.

In C, what's the difference between a file and a stream?
How do save to a file or to a stream?

C provides a number of functions for this, such as fprintf(),
fwrite(), fputc(), etc. However, there is no particular guarantee
that what you are writing to isn't a volatile file system (RAM
disk or similar) that will lose its memory on powerdown, nor is
there any guarantee that when fprintf() returns, the data has
actually made it to the disk drive, or that after it has made it
to the disk drive, it's actually written on disk (as opposed to
an on-drive cache).

Gordon L. Burditt
 
J

Joe Wright

Hi,

In sudden power off, How to backup means in which format(files,
streams) & when to backup in C.

Thanks,
SAI
When somebody kicks your plug out of the wall, you are hosed. All that
power-off stuff is done by the BIOS and/or OS and they won't tell you.
There is nothing to do. R.I.P.
 
W

Walter Roberson

Joe Wright said:
When somebody kicks your plug out of the wall, you are hosed. All that
power-off stuff is done by the BIOS and/or OS and they won't tell you.
There is nothing to do. R.I.P.

Your answer is written in absolute terms -- you used the word "all"
and made the specific claim "they won't tell you".

Anything to do with power failure notification is system specific
and in comp.lang.c one should not assume any particular system
behaviour.

It so happens that your statement is incorrect on some operating
systems, including SGI IRIX and including Linux.


http://en.wikipedia.org/wiki/SIGPWR
http://wlug.org.nz/SIGPWR
 
M

Mark McIntyre

On Tue, 25 Jul 2006 15:37:21 +0000 (UTC), in comp.lang.c ,
It so happens that your statement is incorrect on some operating
systems, including SGI IRIX and including Linux.

.... and Windows. However typically unless you have a UPS or other
battery supply, you get about a hundredth of a second to do anything
in any OS...
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
W

Walter Roberson

... and Windows. However typically unless you have a UPS or other
battery supply, you get about a hundredth of a second to do anything
in any OS...

Tsk, overly specific on the timelines ;-)

Some OSes only run on systems which are designed to provide longer
usable emergency power-shutdown times.

Besides, 1/100th of a second might well be long -enough- on
systems with battery-backed (or capacitor-backed) hard disk controllers,
or systems with SDRAM or other writable non-volatile memory.

At (say) 1 Gops (10^9 core operations per second), 1/100th of second
is enough for 10 million core operations. Even with the usual
"drop by a factor of 10 for each level of cache", one can expect
several tens of thousands of real memory operations, and the speed
of your permanent storage (e.g., disk drives) typically is
the limiting factor.

It's been some time since I had a disk soft corrupted due to
power failure, and much longer yet since the last hard corruption
due to power failure: systems these days typically last long enough for
a drive cache flush. But brownouts (not bad enough to be
detected as power failures) have caused me the occasional trouble
within the last year.
 
K

Keith Thompson

Mark McIntyre said:
On Tue, 25 Jul 2006 15:37:21 +0000 (UTC), in comp.lang.c ,


... and Windows. However typically unless you have a UPS or other
battery supply, you get about a hundredth of a second to do anything
in any OS...

If the application is properly designed for the purpose, power
failures shouldn't cause much loss of data anyway, even if the
application does nothing special after the power starts to fail. For
example, it might periodically dump (some representation of) its state
to non-volatile storage. You'll only lose data generated between the
most recent completed dump and the power failure. This approach works
equally well for other external events, such as someone "kill -9"ing
the process or whatever the local equivalent is.

This is, of course, off-topic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,979
Members
47,579
Latest member
CharaS3188

Latest Threads

Top