News for hackers. Stuff that matters.
Re:Server Retired After 18 Years Running on FreeBSD 2.2.1 an... by laumars on Sunday January 24, 2016 @02:34PM (#10963676)
To be honest that sounds like a pretty bad set up if you need to manually delete files when you know there's a chance that the system is not only operating on them, but also not stable enough to handle exceptions arising from accessing them.

But arguments about your system aside, you could mitigate user error by installing lsof[1]. eg

    $ lsof /bin/bash
    COMMAND   PID USER  FD   TYPE DEVICE SIZE/OFF NODE NAME
    startkde 1496  lau txt    REG   0,18   791304 6626 /usr/bin/bash
    bash     1769  lau txt    REG   0,18   791304 6626 /usr/bin/bash

[1] https://www.freebsd.org/cgi/man.cgi?query=lsof&sektion=8&man...

You might even be able to script it so you'll only delete a file if it's not in use. eg

    saferm() {
        lsof $1 || rm -v $1
    }
If you do come to rely on that then you'll probably want to do some testing against edge cases; just to be safe.

There are no comments on this comment yet.