restarting process

This is a discussion on restarting process within the Windows Programming forums, part of the Platform Specific Boards category; does anyone here know of a quick and easy way to restart the current process? I mean, let the process ...

  1. #1
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211

    restarting process

    does anyone here know of a quick and easy way to restart the current process? I mean, let the process close, and when it closes, restart it again?

    the only thing that I can think of is injecting a thread into another process which waits for the program (the injector) to close, before it calls CreateProcess or the like to start it again. this is rather dirty, and would involve injecting into a process that I know will always exist, which will likely be a process that is vital to the operation of Windows (like Explorer.exe). this could also lead to problems, since not all of the APIs used for process injection are supported across platforms. for example, some of them do not exist in Win9x. I suppose I could write my own implementations of them, but I dunno, it just seems dirty to me. if it's the only option I'll have to go for it, but there has to be another way.

    any ideas or suggestions are appreciated. thanks in advance.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Sure, you should be able to do something like this: create a process which executes the current process again, and then exits itself. You shouldn't need to "inject a thread into another process" . . . .

    I'm not sure how this could be done in Windows, but in Linux, you can do it with something as simple as this.
    Code:
    execvp(argv[0], argv);
    http://www.opengroup.org/onlinepubs/...ions/exec.html
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211
    thanks dwks, that works perfectly.

    now, if I could only find where execvp is declared to silence a warning it would be perfect. execvp is listed at msdn, but there is no description for it .

    EDIT: nvm, I just added my own prototype for it:

    Code:
    int execvp(const char *, const char **);
    Last edited by Bleech; 11-28-2007 at 11:00 PM.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,668
    Why not just start a new instance of your app and let the old one exit?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 10:05 AM
  2. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  3. Replies: 2
    Last Post: 04-04-2008, 09:42 AM
  4. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  5. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21