Brain Teaser Extended

Hi Gurus,
To the Brain Teaser, if I add another condition, say the executable should not be altered, how the program should be altered? (no perl please, purely C). I forgot to mention this condition my staff had mentioned. ( forgot then and got now :smiley: )

The program executed the first time should do some thing and if executed again, should do nothing. (not to encounter "file missing" error though :slight_smile: )

Regards
RK Veluvali

You want a self modifying executable which is not allowed due to the separation and protection of the text segment which is shared and readonly.

For the first time, when the executable is run -

check if file /var/tmp/epoch_seconds is available
if available
  unlink and exit
  don't run
else
  create the above file and terminate
fi

with this, it will run only for the first time and not for the second time

Does the program support DB interaction? If so reserve a flag for this application and flip it as per usage.

On first run, the program could modify its mtime (or some portion of mtime like microseconds) to some specific value and then on subsequent runs if it sees that mtime quit.