[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Removing (the file of) a running program [was: Trixie DHCP client migration ...]



On Mon, Jan 12, 2026 at 08:03:39PM -0500, Greg Wooledge wrote:

[...]

> This left me with the dhcpcd-base package installed, isc-dhcp-client
> in the "rc" state, and a dhclient process still running(!).  I didn't
> even think that was possible on Linux -- for a process to continue
> running after its program file on disk has been unlinked.

I remember it always was "normal" on Unices (I even remember poking
fun at the poor Windows sods who couldn't pull off that trick). The
background is that you just remove the directory entry (the file
still exists as long as it is referenced, i.e. at least while the
process runs; actually, on Linux, with its proc file system you even
might revive it by looking through /proc/<PID>, I think).

So I made an experiment. This is /tmp/foo.c

  #include <stdio.h>
  #include <unistd.h>

  int main(int argc, char *argv[])
  {
    int i = 0;
    while(1) {
      printf("Hello %d\n", i++);
      sleep(2);
    }
  }

"Make foo" generates an executable /tmp/foo. Invoking it goes
counting. Now, from another xterm, do "rm /tmp/foo". The counting
continues happily. I didn't try the revive trick, but I'm convinced
it might work.

So we still get to poke fun at the poor windows sods ;-D

Now trying to *edit the executable file in place* might get you
a -ETXTBSY (Text file busy). Another kettle of fish.

Cheers
-- 
tomás

Attachment: signature.asc
Description: PGP signature


Reply to: