CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2005
    Posts
    1

    How to save a "state" of a process

    Hi All,

    I want to suspend a process and save a "state" of this process so that I can resume the process from this point at a later time. Is it possible to save all the information of a running program/process so that next time if I lanch this program or create this process, I can load those previously saved information into memory and resume from that point. What I want to do exactly is just like making a checkpoint in some games. But I don't know what information should be saved and how to do this. I hope someone can give me a hint, thanks in advance!


    Regards,

    A.

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: How to save a "state" of a process

    I'm almost certain that will be impossible.
    Just think about it. Especially for games, they write stuff to the graphics card, program pixel shaders on the graphics card, etc...
    When a window is opened, a HWND is given to the window. The application knows this HWND, but when you restart the applicatio, this HWND is completely different, so the app won't work correctly. You can't force Windows to create a window with a given HWND. The same holds for other handles, like files etc
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: How to save a "state" of a process

    Hey Marc,
    This technique is possible to do, and frequently used by game developers, and is called savegame file. Main question here is: what information we need to startup process from prevoius state? For a game you do not have to dump all registers, dump whole memory, often you cannot do that due to insufficient access privileges. Saving state of all necessary objects in the game is good enough.
    Achilles, just think what data is necessary to invoke your proccess from previous state, and load it from file on startup. When process exits, save all necessary data to file, or registry, or whatever storage area you wish.

    thats my opinion
    Hob
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: How to save a "state" of a process

    Quote Originally Posted by Hobson
    Hey Marc,
    This technique is possible to do, and frequently used by game developers, and is called savegame file. Main question here is: what information we need to startup process from prevoius state? For a game you do not have to dump all registers, dump whole memory, often you cannot do that due to insufficient access privileges. Saving state of all necessary objects in the game is good enough.
    Achilles, just think what data is necessary to invoke your proccess from previous state, and load it from file on startup. When process exits, save all necessary data to file, or registry, or whatever storage area you wish.

    thats my opinion
    Hob
    Of course... but I interpreted the question as he/she wanted to save the state of any application, not specifically his/her application....

    So, Achilles: do you want to save the state of your own application or of another app of which you don't have the source code?
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  5. #5
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: How to save a "state" of a process

    Oh yes, thats a way I did not think of. Very much depends of understanding a question But also this is at least partially possible I think, but not at application level. Windows XP hibernation works in this way, but it stores to disk not only process information, but also system state. I also assume that not every application would dehibernate without a problem.

    Hob
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  6. #6
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: How to save a "state" of a process

    Quote Originally Posted by Hobson
    Oh yes, thats a way I did not think of. Very much depends of understanding a question But also this is at least partially possible I think, but not at application level. Windows XP hibernation works in this way, but it stores to disk not only process information, but also system state. I also assume that not every application would dehibernate without a problem.

    Hob
    Yes, Windows Hibernate works that way, but it write the state of the entire operating system to disk. You can't hibernate only 1 program, because as I already said, you can't recreate a window with a given HWND (similar for file handles, mutexes, etc...)
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  7. #7

    Re: How to save a "state" of a process

    If you just wanted to suspend a thread for a certain amount of time one might be able to use the SuspendThread() function, documented here. If that's not what you're looking for, there might be something of interest in that list of related functions to the left.

  8. #8
    Join Date
    Mar 2005
    Location
    Canada Alberta
    Posts
    80

    Re: How to save a "state" of a process

    Saving the "state" of the process would be the equivelant of taking a snap shot of the ram/VM that is being used by that program at that instant and some how loading it again (this is an extremely inefficient method but it should work, in theory )
    In C, you merely shoot yourself in the foot.

    In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."

  9. #9
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: How to save a "state" of a process

    Quote Originally Posted by barrensoul
    Saving the "state" of the process would be the equivelant of taking a snap shot of the ram/VM that is being used by that program at that instant and some how loading it again (this is an extremely inefficient method but it should work, in theory )
    No, it won't work. Didn't you read my replies?
    You can't recreate the windows with the exact same HWND as before, you can't create file handles with the exact same file handles as before, same for events, etc etc...
    Last edited by Marc G; December 20th, 2005 at 09:17 AM.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured