Pause An App Using Terminal 3


Pause An App Using Terminal


This will be the first post back in what seems like a year. Due to the amount of work Uni piles on you I had to cut back the amount I could write on this site. Anyway I have a cool post to kick off the holidays and I should be able to write every day till at least February. As the title implies this post is all about pausing an application using Terminal. If you have an app that is running that you want to give up its CPU time but not quit the app, this trick may come in handy. It takes a little bit of work to figure out what is happening, but it is really useful.

To start we need an application running to use as a test. Start a video or run iTunes, this is so you can instantly see the effects and to make sure the command is working. Once you have done this open Terminal located in the Utilities folder. The first step is to find the process ID of the application you want to quit. This can either be done from Activity Monitor, make use the column is visible from the View menu. Since we have Terminal open I am going to show you a Terminal command to achieve the same result. The process ID is  a number your system assigns to an application.

To find the process ID for the application you want to quit type the following:

ps -ef

This will list every process currently running on your system. There is quite a lot and we need to trim this list down. However if you scroll to the top of the list that has been generated you will notice a column header called “PID” this is the column with the process ID’s, we will need to remember the second column.

To find what we want we will run a search command to only pick out the bit of information we need. This is as follows for the application Spotify, replace the end word for the application you want to quit. Case is important at this stage.

ps -ef | grep Spotify

This should reproduce something similar to the following.

501  3219   138   0   0:33.67 ??         1:22.62 /Applications/ -psn_0_294984

Remember from previously we need to remember the second number, in this case 3464. This is out PID. We can now pause the application. This is done with the following command.

kill -stop 3219

The application will then stop, it will still be in memory but will cease to use any CPU time. You will not be able to do anything with the application until restarts. This is done with the following command.

kill -cont 3219

It will then resume what ever it was doing before the stop command. Nifty.

You can also kill the program from Terminal, you can use two commands. Either

kill -abrt 3219

Which will abort the program however I find it to be a bit unreliable and will usually crash the program. The best way is to use the killall command.

killall Spotify

This will kill the program.

I find the stop command quite useful, usually with Firefox, since it can take up a lot of CPU doing what ever it does, a quick pause so I can do something else can usually save 5 minutes since I have full CPU time.

If you have any questions or comments, please leave a comment.

If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.

Where To Next?

  • Subscribe To Mac Tricks And Tips