6

In Linux, if I want to get the file descriptors of a process, I would go to the following directory:

/proc/<pid>/fd

But in UNIX V7, the /proc directory does not exist.

2
  • 1
    It may be possible that lsof could be made to work on V7 and that it would show you the file descriptors of a process. Commented May 19, 2017 at 20:57
  • AFAIK, the idea of the proc filesystem came to Unix via Unix's successor Plan9 from Bell Labs, which started in the mid-80s and was released in 1992. Anything older than that wouldn't have it, since the idea didn't exist. After that, it depends on how fast the particular developers were adopting the idea. Commented Jun 3, 2017 at 9:01

1 Answer 1

11

You can't do this in Unix v7 unless you resort to poking around in /dev/kmem. This is basically what ps(1) does so it's not unheard of.

If you're interested in pursuing this, look at the source for ps to see how it locates the process table in kernel memory, then make a similar tool that reads the global file table. The next step will then be to locate the user area for each process so that you know which files are open by whom. This may require you to look in /dev/swap for processes that are swapped out, but I think the ps sources have an example of how to do that as well.

4
  • Processes can just read kernel memory? Isn't that a bit of a security problem or does the kernel only expose certain parts?
    – cat
    Commented May 19, 2017 at 18:15
  • 1
    @cat ps could have been setuid or setgid with permission on /dev/mem limited, but this doesn't appear to have been the case on the V7 distribution tapes.
    – Random832
    Commented May 19, 2017 at 20:00
  • 2
    @cat I ran out of time to edit, just to mention, ps reading /dev/mem or /dev/kmem (it was /dev/mem on V7) was still the case well into the 90s on some Unix and Linux systems. You can find the linux version that does this from 1994 in ibiblio.org/pub/historic-linux/ftp-archives/sunsite.unc.edu/… (the psmisc package shown there uses /proc, the kmem-ps package contains a fstat/fuser command)
    – Random832
    Commented May 19, 2017 at 20:10
  • 1
    On a modern Internet-connected system, world-readable kernel memory is a big problem. But in 1978, there was much less risk of malicious users getting into your system.
    – Ken Gober
    Commented May 20, 2017 at 23:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .