A way for saving data after closing a C program [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to use the c-programming language to built a small database for students. Only the admnistrator should enter delete or modify the data. I have developed this program in C. But when i close my program, the data is lost. At the beginning i thought to store these data in files (like xml) but know i thinking to store these data on hardware (harddisk or sd-card). Is it possible? Any suggestions?

You could write a separate program which acts as a "server" - that is, it runs continuously and communicates only through some sort of network interface - named pipes or TCP/IP or whatever. When your "client" program starts up it attempts to establish a connection with the server - if it does not find the server it starts it up and then establishes communications with it. Once the "server" is found the "client" requests any saved data from the "server", which the "server" then returns if it has any. When the "client" decides to shut down it first communicates with the "server", passing any data it wishes to save to the "server" which then stores it (perhaps in a file, perhaps in memory - the implementation is up to you).
Best of luck.

Related

Pass from HC-05 Data Mode to HC-05 AT Command mode by writing some bunch of code [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
My main problem is to reduce the power consumption of the HC-05 Bluetooth module. As it may be known, such a module consumes lower and lower energy when it is in the AT Command Mode (between 1.5 and 3 mA current). Since my project requires sending real time data that change every 15seconds, I want to keep the module in the AT command mode in the 15seconds that the HC-05 don't receive any data. I obviously believe that this kind of idea/solution will dramatically save the energy of the module. In other words, instead of keeping the module in data mode permanently, it will be set in data mode during 15seconds, and in AT command mode during 15seconds, after that it returns to the data mode and still 15seconds etc... I want to know is there any solution for that ? For example writing a bunch of C code (since my Hc-05 is directly connected to an STM32 board) to pass for the AT commande mode every 15seconds
Thanks in advance.
In the absence of any sample code, the answer to your only explicit question
I want to know is there any solution for that ?
is, "Yes."

How to implement reliable UDP to transfer files quickly? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to transfer some files from one point to another. Files are sensitive so transfer has to be reliable, but if I use TCP to transfer files than the speed gets slow.
How do I create a reliable version of UDP that will transfer files quickly?
What I am doing is sending an acknowledgement for every received packet. But it is reducing my transfer speed.
Is there any way that exists without sending an acknowledgment for every received packet? Can I somehow keep track of lost packets efficiently and request those packets only?
Note:: I am sending a sequence number with every packet
I guess that you could put a count value in each packet and if you received a packet that skips a value then you know that you've lost one or more and could request a resend.
However, you're starting to implement the functionality of TCP by coding for packet loss. Is there a reason why you couldn't implement that instead?
Certainly if I was transferring sensitive data I wouldn't choose UDP myself.

How to get a disk's sector number of the INODE. C, Linux? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Is there a way to "translate" INODE number into the disk sector number by using C?
No, standard C does not provide any support for this.
The inode number designates an entry with information about the file in a file system. That entry has further information for the device driver, which would determine where it is on the storage device. This information is normally accessed only by device drivers, not standard user programs. Also, a file may have its parts stored in multiple places on disk, not a single sector or contiguous sequence of sectors.
If you are writing a device driver, there are structures and kernel services you would need to know about in order to write the driver. You could learn about these from textbooks or reference materials.
Largely the same knowledge would be required to write a user-level (but privileged) program to read the file system and device data and interpret it to determine where the parts of the file are stored.

What Linux Port is always writing [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am experimenting reading (and eventually writing) serial ports in C. I want to be able to connect to a port on debian and read in some data but I need a port that is writing (speaking). I am new to linux programming.
What port, that will definitely be present and talking in debian, can I connect to to read some data in?
Can you also suggest a port I can eventually use to write to aswell?
I've tried connecting to /dev/ttyUSB1 that this example uses but that port doesn't exist.
I would suggest either open /dev/random (or /dev/urandom) as Paul suggests or create your own socket and read/write to that. Don't just pick an arbitrary socket and hope it has information that no other process needed.
If this is your first time working with sockets I would also suggest that you try playing around with things in a language like python simply because you don't need to recompile to see where you went wrong and the warnings are often more readable (take a look at https://docs.python.org/2/howto/sockets.html)
As a side note: If you have access to an arduino you might like to try connecting to that socket (usually something like ser = serial.Serial('/dev/ttyACM0', 9600) in python).

Saving session or process state in linux [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have to create a functionality for my project like saving session and further resume it from the same position in future. So I need to know how save the state of a process and then read from disk and resume it afterwards.
PS. The application is an interactive shell for a language and I need to extend it include a save session and resume session. But we want the code to be generic enough to be used in other places too.
This is quite a challenging task. The basic idea is to interrupt the process with a signal, at which point the OS puts the state of all registers (including the instruction pointer) in memory where you can access them if your shell has spawn the process you want to interrupt.
For more detail, you can look how checkpointing utilities handle that problem:
dmtcp
BLCR
Criu
That is quite hard to answer in general other than “save the program's entire state to a file and load it from there on resume”. That can be very tricky because you might need to restore things like file handles and sockets, which may not even be possible if things have changed during the suspended state. But it may suffice for you to support something less than that and only save the information necessary to approximate the previous state (e.g., save the list of program files to load, or the save user's command history and replay it, etc).

Resources