bash process uses 90% CPU, comes back on computer restart

Solution 1:

Until replaced by zsh in macOS 10.15, bash was the standard shell of the Mac operating systems – i.e. the standard program to interface with the operating system’s Darwin underpinnings (technically, /bin/sh is the standard shell on a Mac, but that was a copy of /bin/bash from OS X 10.3 to macOS 10.15). It is the process that is launched when you open a Terminal.app window – an interactive shell.

bash can also be launched without a terminal window – a non-interactive shell –, for instance to execute shell scripts, often denoted by the file suffix .sh. That is the case here – bash is running the script /usr/bin/stkLaunchAgent.sh, and something in this script is keeping your system busy.

Now, as of the time this question was asked, /usr/bin/stkLaunchAgent.sh is not part of an OS X install – it is some kind of third party addition and as such is not present on my system, meaning I can only guess, but I’d say:

  • from its name part “LaunchAgent” and the fact it starts with your system, that it is triggered by a LaunchAgent – a small definition file used by OS X’ launchd, the system mechanism for starting scripts and non-interactive programs on schedule, boot or other events. That part I‘d qualify as an educated guess.
  • from the fact your troubles began with the installation of your Vertex SSD, and the fact that the crucial difference between SSDs and HDs is the first do not take kindly to defragmentation and similar low-level interventions into their structure, that the script launched by the agent in question might be trying to do some operation on the drive the Vertex SSD does not accept – which keeps the script running and bash busy. Now, that part is only a wild, wild guess, but…

How to find out what the script does:

Open a Terminal window and do open -e /usr/bin/stkLaunchAgent.sh to have a peek into the shell script (that command will open it in TextEdit – terminate it in Activity Monitor first) – that should give you the means to see what exactly is running.

How to get rid of it:

You’ll have to get rid of the LaunchAgent, if it is indeed one. launchd LaunchAgent files are in plist format and found in

  • ~/Library/LaunchAgents – for the current user account only
  • /Library/LaunchAgents – for all user accounts
  • /System/Library/LaunchAgents – system level agents (should not by rights be found here!)

They are usually named in reverse domain notation (tld.domain.process.plist). Depending if the user account of your runaway bash is yours or not, you should look in one of the first two locations above for a likely plist (if you have Xcode installed, you can QuickLook them easily). The correct procedure to stop it is to remove it from launchd’s process list through

launchctl unload tld.domain.process

which will unload and stop the process (note you omit the plist suffix).

There is also a GUI for handling launchd files, Peter Borg’s Lingon (make sure to get “Lingon”, not “Lingon 3”, which is a dumbed down version safe for vanilla use), which might be more convenient than manually rooting through the file locations.

Background:

  • bash on OS X by David Miller (from 2004, but still a good introduction)
  • launchd article on Wikipedia

Solution 2:

I looked inside the file and learned its part of the Save to Kindle application that I installed a few weeks ago. The app has an uninstaller in /Applications, so I did that instead of deleting the .sh directly. Worked.