473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
Jul 22 '05 #1
5 5843
"Mike" <mi*********@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.
Jul 22 '05 #2
mi*********@yahoo.com (Mike) wrote in
news:bb*************************@posting.google.co m:
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.
Jul 22 '05 #3
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

Jul 22 '05 #4
In message <0J***************@newssvr15.news.prodigy.com>, Thomas
Matthews <Th****************************@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
Jul 22 '05 #5
[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...


Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eric | last post by:
Hi, I'm used to C/C++ where if you "new" something you really need to "delete" it later. Is that also true in javascript? if i do "mydate = new date();" in a function and dont "delete mydate" when...
4
by: Asipu | last post by:
The problem is quite difficult and i'm starting to think that it's impossible to accomplish.. Suppose you have C.exe. When you run C.exe, it must change his 0x4e's byte into 0xff.. Of course,...
8
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: ...
8
by: Richard Arthur | last post by:
This is a weird problem. 1) I use MediaDet to save a bitmap in a temporary file. 2) I create a bitmap using that temporary file's name. 3) I use the bitmap. 4) I want to destroy the file when...
2
by: Jason | last post by:
Can I make a vb.net executable delete itself, like a vb script can?
2
by: taroz | last post by:
Hi, I'm trying to create an installation package that auto delete itself after the execution. The problem is when execute the command --cmd /c "rd /s /q" <--. I used the "spawn"...
1
by: arnuld | last post by:
I am trying to write a program that creates and renames log file on the system. I have created the initial design ( which of course is not compilable). Just asking whether this is the right way to...
2
by: SCPOS | last post by:
Cannot delete X: It is being used by another person or program. Close any programs that might be using the file and try again. Of course I have tried closing any programs I know of that may be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.