Error when detaching volume using hdiutil on OS X

Bas Smit picture Bas Smit · Oct 28, 2010 · Viewed 8.1k times · Source

Ive got a program that runs on Mac OS 10.5.8. The program runs a continuous cycle where it mounts an image, installs a browser plugin and unmounts the image again. If I leave this program running I eventually end up in a situation where I get the following error "fork: resource temporarily unavailable". In the activity monitor I can see that several hundreds of processes called diskimages-helper are running. Does anyone know why this happens and how I can avoid it? Below are the commands I use during one cycle of the program.

# First I remove the plugin
rm -rf "/Library/Internet Plug-Ins/my.plugin"

# If the mount exists I unmount it
hdiutil unmount [mount] -force

# If that doesnt work I detach the device
hdiutil detach [device] -force

# Then I mount the image
hdiutil mount [image]

# I install the plugin
installer -package [package] -target /

# Unmount
hdiutil unmount [mount] -force

# And if necessary detach
hdiutil detach [device] -force

Answer

Gordon Davisson picture Gordon Davisson · Oct 29, 2010

You need to always detach the disk image -- unmounting it unmounts the filesystem, but leaves disk image attached to a /dev/disk* entry, with a diskimages-helper process running to handle it. Note that hdiutil detach will take care of unmounting the volume for you (provided Disk Arbitration is running), so you can just skip the unmount step.