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 $$ COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME 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): NAME fuser - identify processes using files or sockets [...] DESCRIPTION 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) (BSD). The fuser(1) command even has a -k (kill) option to send a signal to every process that's holding a directory open.