Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用c编程在重新启动后保留值_C_Embedded Linux - Fatal编程技术网

如何使用c编程在重新启动后保留值

如何使用c编程在重新启动后保留值,c,embedded-linux,C,Embedded Linux,任何人都可以帮助,要求在重新启动服务器后保留变量的值 假设我在一台服务器上为一个进程设置了多个C编程文件,我想在重新启动服务器之前保存一些值,一旦重新启动,我想根据上次重新启动的值(即…,状态)执行一个操作 我不确定它是否会起作用,但我很想知道一个全局静态 威尔持有早期各州的价值观 ex:静态int早期_状态[10] 注意:我的要求是在Linux系统上使其更简单,我总结了单个进程的情况将数据存储在一个数据库中。然后,它将作为常规内存在程序中运行和访问,但将由操作系统保留在映射文件中。重新启动时,

任何人都可以帮助,要求在重新启动服务器后保留变量的值

假设我在一台服务器上为一个进程设置了多个C编程文件,我想在重新启动服务器之前保存一些值,一旦重新启动,我想根据上次重新启动的值(即…,状态)执行一个操作

我不确定它是否会起作用,但我很想知道一个全局静态 威尔持有早期各州的价值观

ex:静态int早期_状态[10]

注意:我的要求是在Linux系统上使其更简单,我总结了单个进程的情况

将数据存储在一个数据库中。然后,它将作为常规内存在程序中运行和访问,但将由操作系统保留在映射文件中。重新启动时,重新映射现有文件,它将包含最后一个状态


但是,需要注意-如果重新启动或终止中断了映射数据访问,则状态可能不一致。可能需要对数据进行某种验证。

将数据存储在文件或数据库中如何?您可以为应用程序创建一个配置文件,并在需要时从中存储/检索数据。我们可以将数据存储在文件或数据库/闪存中并检索信息,但这将导致分析我希望有其他配置文件替代方法..C是一种编译的编程语言而不是脚本语言-运行的代码是一种编译的二进制代码而不是“C编程文件”。与任何进程一样,运行时数据也是不稳定的。将状态存储在文件中是一个显而易见的解决方案——内存映射文件甚至可以看起来像您所要求的持久数据。但是,如果重新启动不受控制,数据可能不一致。“导致分析”?这是什么意思?没有什么魔法可以让易失性内存持久化,或者更重要的是,可能会导致进程在重新启动时分配相同的内存。你对计算机的工作原理有着根本性的误解,而不是C语言编程。
for retaining the updated values of variables after rebooting , it is necessory to store the values of variables in permanent memory as the temporary memory get erased when power off happens .
So for this you need to create the Configuration file( NOTE : Create in R+ mode because other modes will erase the data while creating the file if it is already exist) .  
- Create a file at starting of the execution in R+ mode .
- Write the variable in file which you need to retain , here you need to write the variable again and again where your program is modifying that variable , and here you need to take care of position of variables in the file .
- Use the fflush(file ptr); function to flush the file stream into file ( This is necessory to put data into hard drive for each variable modification , it will allows you to kill the process abnormally) .
- After reboot run the process(if your requirement is like , you need to start process with bootup then make it zombie ) and read and initialize the variables form the file and use in the program for further processing .