Restarting the process!! Pliz help
-
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
-
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
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;
-
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;
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
-
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
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;
-
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;
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