Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Restarting the process!! Pliz help

Restarting the process!! Pliz help

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelptutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mpapeo
    wrote on last edited by
    #1

    I want to restart the process. At first i created the process using createprocess() and then suspend it using suspendthread() and then i saved its state and information about it e.g. baseadress, context, state e.t.c in a binary file, after that i terminate it. Now i want to recreate it using its suspended state information. Pliz help me about this because i tried to use the functions below but the process doesnt restart again or atleast how to recreate a process using information from a previous saved information. case 5://checkpointing SuspendThread(pi.hThread);// identifies thread to suspend printf("\nThe thread of ID: %d",pi.dwProcessId); printf(" has been suspended!\n"); GetLastError(); GetThreadContext( hProcess, // handle to thread with context lpContext // address of context structure ); GetLastError(); regnum = 0; base = 0; fp = fopen("checkpoint.bin","w"); if( fp ) while (base < sinfo.lpMaximumApplicationAddress) { VirtualQueryEx(hProcess, base, &mbi, sizeof(mbi)); if (mbi.State == MEM_COMMIT) state = "Used"; else if (mbi.State == MEM_FREE) state = "Free"; else if (mbi.State == MEM_RESERVE) state = "Reserved"; else state = "Unknown"; printf("\nREGION #%d\nState:%s\nBase Address:%p\nAllocation Base:%p\nAccess Protection: %08x\nRegion \ Size: %08x\nProtection: %08x\nType: %08x\n", regnum, state, mbi.BaseAddress, mbi.AllocationBase, \ mbi.AllocationProtect, mbi.RegionSize, mbi.Protect, mbi.Type); base = (LPVOID)((unsigned long)mbi.BaseAddress + (unsigned long)mbi.RegionSize); /* make base point to one byte past the end of current region, which is either the beginning of the next region, or the beginning of the gap before the next region. VirtualQueryEx() with this address will tell us about the next region in either case */ regnum++; //printf("Enter the file-name to save the Memory Information: ",fname); //scanf ("%s",fname); fprintf(fp,"\nREGION #%d\nState:%s\nBase Address:%p\nAllocation Base:%p\nAccess Protection: %08x\nRegion \ Size: %08x\nProtection: %08x\nType: %08x\n", regnum, state, mbi.BaseAddress, \ mbi.AllocationBase, mbi.AllocationProtect, mbi.RegionSize, mbi.Protect, mbi.Type); }//inner while Sleep(3600); TerminateProcess(pi.hProcess, 0); break; case 6://restarting the process in the other machine lpBaseAddress = 0; hProcess = mbi.BaseA

    G 1 Reply Last reply
    0
    • M mpapeo

      I want to restart the process. At first i created the process using createprocess() and then suspend it using suspendthread() and then i saved its state and information about it e.g. baseadress, context, state e.t.c in a binary file, after that i terminate it. Now i want to recreate it using its suspended state information. Pliz help me about this because i tried to use the functions below but the process doesnt restart again or atleast how to recreate a process using information from a previous saved information. case 5://checkpointing SuspendThread(pi.hThread);// identifies thread to suspend printf("\nThe thread of ID: %d",pi.dwProcessId); printf(" has been suspended!\n"); GetLastError(); GetThreadContext( hProcess, // handle to thread with context lpContext // address of context structure ); GetLastError(); regnum = 0; base = 0; fp = fopen("checkpoint.bin","w"); if( fp ) while (base < sinfo.lpMaximumApplicationAddress) { VirtualQueryEx(hProcess, base, &mbi, sizeof(mbi)); if (mbi.State == MEM_COMMIT) state = "Used"; else if (mbi.State == MEM_FREE) state = "Free"; else if (mbi.State == MEM_RESERVE) state = "Reserved"; else state = "Unknown"; printf("\nREGION #%d\nState:%s\nBase Address:%p\nAllocation Base:%p\nAccess Protection: %08x\nRegion \ Size: %08x\nProtection: %08x\nType: %08x\n", regnum, state, mbi.BaseAddress, mbi.AllocationBase, \ mbi.AllocationProtect, mbi.RegionSize, mbi.Protect, mbi.Type); base = (LPVOID)((unsigned long)mbi.BaseAddress + (unsigned long)mbi.RegionSize); /* make base point to one byte past the end of current region, which is either the beginning of the next region, or the beginning of the gap before the next region. VirtualQueryEx() with this address will tell us about the next region in either case */ regnum++; //printf("Enter the file-name to save the Memory Information: ",fname); //scanf ("%s",fname); fprintf(fp,"\nREGION #%d\nState:%s\nBase Address:%p\nAllocation Base:%p\nAccess Protection: %08x\nRegion \ Size: %08x\nProtection: %08x\nType: %08x\n", regnum, state, mbi.BaseAddress, \ mbi.AllocationBase, mbi.AllocationProtect, mbi.RegionSize, mbi.Protect, mbi.Type); }//inner while Sleep(3600); TerminateProcess(pi.hProcess, 0); break; case 6://restarting the process in the other machine lpBaseAddress = 0; hProcess = mbi.BaseA

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      You can't do what you are attempting. Process management is up to the operating system. Does the comment "restarting the process in the other machine" mean that you are attempting to move processes from one machine to another? That absolutely won't work either. You need to design your application so that it can save its state to a file when it exits, and restore its state from a file when it starts up.


      Software Zen: delete this;

      M 1 Reply Last reply
      0
      • G Gary R Wheeler

        You can't do what you are attempting. Process management is up to the operating system. Does the comment "restarting the process in the other machine" mean that you are attempting to move processes from one machine to another? That absolutely won't work either. You need to design your application so that it can save its state to a file when it exits, and restore its state from a file when it starts up.


        Software Zen: delete this;

        M Offline
        M Offline
        mpapeo
        wrote on last edited by
        #3

        When it starts up? Do you mean when i re-run it again. My application automatically save the state of a process when i suspend it. But now i want to use this state to restart/recreate this process again, e.g. like if i can send this information to another computer. It was done before but this was in unix. Check this: Restoring[^] oam

        G 1 Reply Last reply
        0
        • M mpapeo

          When it starts up? Do you mean when i re-run it again. My application automatically save the state of a process when i suspend it. But now i want to use this state to restart/recreate this process again, e.g. like if i can send this information to another computer. It was done before but this was in unix. Check this: Restoring[^] oam

          G Offline
          G Offline
          Gary R Wheeler
          wrote on last edited by
          #4

          mpapeo wrote: When it starts up? Do you mean when i re-run it again. Yes. mpapeo wrote: My application automatically save the state of a process when i suspend it. This won't work under Windows. There are too many external factors involved that you can't control. mpapeo wrote: It was done before but this was in unix. I thought that might be the case. mpapeo wrote: Check this: Restoring[^] I skimmed through the article. They are describing the approach I recommended. The application saves its state in a file, and then can reload that file when it runs again. Saving the process memory space and restoring it won't work (especially moving it from one machine to another) because the contents of the memory space includes items that you can't control.


          Software Zen: delete this;

          M 1 Reply Last reply
          0
          • G Gary R Wheeler

            mpapeo wrote: When it starts up? Do you mean when i re-run it again. Yes. mpapeo wrote: My application automatically save the state of a process when i suspend it. This won't work under Windows. There are too many external factors involved that you can't control. mpapeo wrote: It was done before but this was in unix. I thought that might be the case. mpapeo wrote: Check this: Restoring[^] I skimmed through the article. They are describing the approach I recommended. The application saves its state in a file, and then can reload that file when it runs again. Saving the process memory space and restoring it won't work (especially moving it from one machine to another) because the contents of the memory space includes items that you can't control.


            Software Zen: delete this;

            M Offline
            M Offline
            mpapeo
            wrote on last edited by
            #5

            Gary R. Wheeler wrote: I skimmed through the article. They are describing the approach I recommended. The application saves its state in a file, and then can reload that file when it runs again. Saving the process memory space and restoring it won't work (especially moving it from one machine to another) because the contents of the memory space includes items that you can't control. so do you mean it can be difficult in windows to implement this Gary R. Wheeler wrote: mpapeo wrote: When it starts up? Do you mean when i re-run it again. Yes. Well if that is the case then it will be part of what i want. Because the process i am creating prints numbers on the screen. But i suspend it and save its state and then when i re-run it it then continues to print numbers from where it left i knew i will be moving to somewhere in my research. You can give you email so that i sed you the code oam

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups