Re: [SLUG] Simple question

From: Dylan William Hardison (dylanwh@tampabay.rr.com)
Date: Sun Feb 29 2004 - 23:37:39 EST


Spake Joey Dale on Sunday, February 29, 2004 at 10:27PM -0500:
> Hear is a nother question. Everyone jokes about rm -rf / as root but
> what would happen, (I know what the commad would do) what would happen
> when it got to /bin/coreutils and removed rm?
>

Well, rm would continue on merrily deleting everything, including
itself. It deletes itself from the harddrive, but it is still running
in memory.

You can test this, without hosing your system, too! :)

--- suicide.c ---
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
    /* print a message to the user */
        printf("I, %s, shall unlink myself now.\n", argv[0]);
        
        /* remove thyself! */
        unlink("suicide");
        
        /* Say goodbye */
        puts("Goodbye, cruel world.");
        exit(0);
}
--- end ---

now, if you put that in a file called
suicide.c, and run gcc -o suicide suicide.c,
run ./suicide and it'll remove itself.

---
% gcc -o suicide suicide.c

% ls suicide suicide*

% ./suicide I, ./suicide, shall unlink myself now. Goodbye, cruel world ---

Oh, and a similar thing happens when you remove libraries a program needs... the programs will still run. I know this because once I rm -rf'ed /lib by accident... yes, they'll run, but nothing will start...

This is why rm is to be respected. <grin>

-- A formal parsing algorithm should not always be used. -- D. Gries - GPG Fingerprint=D67D 2B75 53C6 9769 30E4 D390 239F C833 F32C F6F6 GPG KeyID=F32CF6F6 ----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 18:22:09 EDT