C++ Program to delete itself after execution ?



 DEVELOP > c-Plus-Plus > C++ Program to delete itself after execution ?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Mike"
Date: 23 May 2004 11:20:26 AM
Object: C++ Program to delete itself after execution ?
Greetings,
I hear this question is one famous interview question . Just
wondering what could be the ways to do this ? Does storing process
info in a text file while running and invoking a small background
script on atexit() a good solution ? if the script keeps pinging for
the pid & binary name and delete it if not found?
Cheers
.

User: "Victor Bazarov"

Title: Re: C++ Program to delete itself after execution ? 23 May 2004 11:28:12 AM
"Mike" <mikelarry88@yahoo.com> wrote...

Greetings,
I hear this question is one famous interview question . Just
wondering what could be the ways to do this ? Does storing process
info in a text file while running and invoking a small background
script on atexit() a good solution ? if the script keeps pinging for
the pid & binary name and delete it if not found?

This has nothing to do with the subject of comp.lang.c++. Please
post your question to a newsgroup that deals with your OS.
.

User: "bartek"

Title: Re: [OT] C++ Program to delete itself after execution ? 23 May 2004 12:02:14 PM
(Mike) wrote in
news:bbab0f01.0405230820.acc5ecd@posting.google.com:

I hear this question is one famous interview question . Just
wondering what could be the ways to do this ? Does storing process
info in a text file while running and invoking a small background
script on atexit() a good solution ? if the script keeps pinging for
the pid & binary name and delete it if not found?

I've heard it's the famous "how do I write a virus" question. ;)
This question is actually quite platform specific, by the way. Please ask
in a forum appropriate for your platform.
For MS Windows, see news:comp.os.ms-windows.programmer.*
For unix-related, see news:comp.unix.programmer
Cheers.
.

User: "Thomas Matthews"

Title: Re: C++ Program to delete itself after execution ? 24 May 2004 08:25:16 AM
Mike wrote:

Greetings,
I hear this question is one famous interview question . Just
wondering what could be the ways to do this ? Does storing process
info in a text file while running and invoking a small background
script on atexit() a good solution ? if the script keeps pinging for
the pid & binary name and delete it if not found?

Cheers

#include <cstdlib>
#include <cstdio>
int main(int argc, char * * argv)
{
remove(argv[0]);
return EXIT_SUCCESS;
}
Provided that the program was launched from a file.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
.
User: "Richard Herring"

Title: Re: C++ Program to delete itself after execution ? 26 May 2004 09:29:07 AM
In message <0Jmsc.340$k_3.267@newssvr15.news.prodigy.com>, Thomas
Matthews <Thomas_MatthewsSpitsOnSpamBots@sbcglobal.net> writes

Mike wrote:

Greetings, I hear this question is one famous interview question
. Just
wondering what could be the ways to do this ? Does storing process
info in a text file while running and invoking a small background
script on atexit() a good solution ? if the script keeps pinging for
the pid & binary name and delete it if not found?
Cheers


#include <cstdlib>
#include <cstdio>

int main(int argc, char * * argv)
{
remove(argv[0]);
return EXIT_SUCCESS;
}

Provided that the program was launched from a file.

.... under a cooperative OS.
--
Richard Herring
.

User: "Kelsey Bjarnason"

Title: Re: C++ Program to delete itself after execution ? 07 Jun 2004 05:46:42 PM
[snips]

#include <cstdlib>
#include <cstdio>

int main(int argc, char * * argv)
{
remove(argv[0]);
return EXIT_SUCCESS;
}

Provided that the program was launched from a file.

And on a platform/implementation that fills argv[0] with useful
information. And on a platform/implementation that allows you to delete
executables. And on a platform/implementation that doesn't lock
executables while they're running. And on a platform/implementation that
doesn't suport symbolic links, or passes the link's target, rather than
the link itself, in usable format, to argv[0]. And on a
platform/implementation for which you have delete/write/whatever
permissions to the file. And...
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER