<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Restore c programs data segment to reset globals in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518464#M844753</link>
    <description>We have a large application we currently fork once per process.  I would like to change it to loop so it does not need to be forked every time, but I beleive we have lots of code where global variabless are changed to non-initialized values, and the process would need all variables as if its the first time its running to behave consistently (no matter what).&lt;BR /&gt;&lt;BR /&gt;Is there a simple way to save the state of all global and static variables before the program runs, and restore the values.&lt;BR /&gt;&lt;BR /&gt;Can I save the entire Text segment before execution, and restore it for the next cycle/thread.  Is it text or data I need ?&lt;BR /&gt;&lt;BR /&gt;What calls can I use to store and retrieve the entire text segment.  &lt;BR /&gt;&lt;BR /&gt;How efficient would this be compared to forking the programs.</description>
    <pubDate>Tue, 05 Apr 2005 15:14:56 GMT</pubDate>
    <dc:creator>James Myers</dc:creator>
    <dc:date>2005-04-05T15:14:56Z</dc:date>
    <item>
      <title>Restore c programs data segment to reset globals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518464#M844753</link>
      <description>We have a large application we currently fork once per process.  I would like to change it to loop so it does not need to be forked every time, but I beleive we have lots of code where global variabless are changed to non-initialized values, and the process would need all variables as if its the first time its running to behave consistently (no matter what).&lt;BR /&gt;&lt;BR /&gt;Is there a simple way to save the state of all global and static variables before the program runs, and restore the values.&lt;BR /&gt;&lt;BR /&gt;Can I save the entire Text segment before execution, and restore it for the next cycle/thread.  Is it text or data I need ?&lt;BR /&gt;&lt;BR /&gt;What calls can I use to store and retrieve the entire text segment.  &lt;BR /&gt;&lt;BR /&gt;How efficient would this be compared to forking the programs.</description>
      <pubDate>Tue, 05 Apr 2005 15:14:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518464#M844753</guid>
      <dc:creator>James Myers</dc:creator>
      <dc:date>2005-04-05T15:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: Restore c programs data segment to reset globals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518465#M844754</link>
      <description>Looping would be much more efficient than fork()'ing a new process although the downside is that you are now singly-threaded. There is no system call to load just the text segment nor would you want to because the text is already loaded but you would need a fresh data segment and there's no way to load that by itself either. You could do a man 3 end but it's not going to help.&lt;BR /&gt;&lt;BR /&gt;My approach would be to put all your globals&lt;BR /&gt;inside a struct and initialize the values once. They remain untouched and each loop uses its own struct copied from the original in a single assignment statement.&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Apr 2005 15:30:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518465#M844754</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-04-05T15:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Restore c programs data segment to reset globals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518466#M844755</link>
      <description>One way would be to write a new routine (say&lt;BR /&gt;save_current_state()) to store the state (i.e current &lt;BR /&gt;values of all the global variables) into a file (in binary &lt;BR /&gt;format). Write another routine, say &lt;BR /&gt;load_saved_state(), and read the saved binary file &lt;BR /&gt;exactly the way you stored. This is a simple technique&lt;BR /&gt;that should work fine. You could even define a new&lt;BR /&gt;large data structure with each field storing one of the&lt;BR /&gt;global variable and write/read the data structure in&lt;BR /&gt;one fwrite()/fread() call. You could name the states&lt;BR /&gt;and store/retrieve multiple states etc. etc..&lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Apr 2005 15:39:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518466#M844755</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-04-05T15:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: Restore c programs data segment to reset globals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518467#M844756</link>
      <description>One more thing. My previous reply is more suited if&lt;BR /&gt;you want to save/restore the state of the program &lt;BR /&gt;from one instance to another (like, if it gets killed and&lt;BR /&gt;restarts with the previous state restored). If you are &lt;BR /&gt;not doing that, then writing to / reading from file is not &lt;BR /&gt;a good idea (slow disk read/write). In that case, you &lt;BR /&gt;could follow my last suggestion, but avoid storing in a &lt;BR /&gt;file and store in memory itself.&lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Apr 2005 15:47:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518467#M844756</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-04-05T15:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: Restore c programs data segment to reset globals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518468#M844757</link>
      <description>I guess my question was more about if there was any useful system calls to grab all memory associated with ALL global variables without having to know what they all are, or access them individually.&lt;BR /&gt;&lt;BR /&gt;This project is mature and has had and will have many people working on it, and theres lotes of variables, and I'm sure they will continue to be added,  If I had a universal type store and restore, those developers would not have to make any changes, they could just keep using globals, and I would not have to worry about missing any.&lt;BR /&gt;&lt;BR /&gt;Is there something to give me the address of this segment I need, and could I just save the whole segmetn and restore the whole thing,</description>
      <pubDate>Wed, 06 Apr 2005 06:40:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518468#M844757</guid>
      <dc:creator>James Myers</dc:creator>
      <dc:date>2005-04-06T06:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Restore c programs data segment to reset globals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518469#M844758</link>
      <description>Where global variables are stored is pretty much down to the compiler/machine architecture combination.&lt;BR /&gt;&lt;BR /&gt;The text segment is the code, not the variables. The data segment stores the variables.&lt;BR /&gt;&lt;BR /&gt;I'm still not sure I understand what it is you are trying to achieve in the first place mind you.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 06 Apr 2005 07:59:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518469#M844758</guid>
      <dc:creator>Stephen Keane</dc:creator>
      <dc:date>2005-04-06T07:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: Restore c programs data segment to reset globals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518470#M844759</link>
      <description>What you are asking for just doesn't exist and you aren't even thinking very deeply. When you say "all global variables", you mean all of "your" global variables but how about global variabes like errno or those associated with library functions (e.g. *optarg,optind,opterr,optopt associated with getopt() --- as an example off the top of my head)? It would be extremely difficult for any utility to distinguish between "your" global variables and the others.&lt;BR /&gt;&lt;BR /&gt;Large projects like yours are a good example why global variables should be used sparingly because there can be all sorts of side effects. Again, the least evil solution to your situation that I can conceive of is to gather all your globals inside a struct (and yes that means code changes though even if this were 50 files, I think I could do it easily in a day).</description>
      <pubDate>Wed, 06 Apr 2005 09:15:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/restore-c-programs-data-segment-to-reset-globals/m-p/3518470#M844759</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-04-06T09:15:37Z</dc:date>
    </item>
  </channel>
</rss>

