[Top][All Lists]

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

Re: [annoyance/non-feature] On OS X, every process is "occupying" CWD, m

From: Greg Wooledge
Subject: Re: [annoyance/non-feature] On OS X, every process is "occupying" CWD, making disk ejects impossible after cd'ing into them.
Date: Tue, 16 Jan 2018 11:26:48 -0500
User-agent: NeoMutt/20170113 (1.7.2)

On Tue, Jan 16, 2018 at 10:36:47PM +0800, Danyel Bayraktar wrote:
> Initially I thought it was specific to the terminal emulator, but it is 
> actually due to the design of OS X. My problem is that when cd’ing into the 
> external drive to run an `ls`, I’m not really “using” it and should be able 
> to eject it. The eject should only be impossible for the time span a process 
> is actually running.

This is not unique to OS X.  Every single Unix-based operating system
works like this.  It has nothing to do with bash.  This is nothing new.
It has been this way since the dawn of time.  You are not going to
change anything.

wooledg:~$ cd /tmp
wooledg:/tmp$ lsof -p $$
bash    4331 wooledg  cwd    DIR    8,6     4096 11141121 /tmp

The cwd is actually held open by the process.  (It doesn't have to
be a shell; that was simply the easiest to demonstrate.)

The issue is EXTREMELY well-known.  There are operating system level
tools to help you identify which processes are holding a directory.
For example, fuser(1):

       fuser - identify processes using files or sockets

       fuser displays the PIDs of processes using the specified files or  file
       systems.   In the default display mode, each file name is followed by a
       letter denoting the type of access:

              c      current directory.

wooledg:~$ sudo fuser /tmp
[sudo] password for wooledg: 
/tmp:                 4331c

Similar tools include lsof(1) (third party but very common) and fstat(1)

The fuser(1) command even has a -k (kill) option to send a signal to
every process that's holding a directory open.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]