AMITIAE - Wednesday 3 October 2012


Command Line Work: New Users and Terminal (9) -- Process Identification and Termination


apple and chopsticks



advertisement


By Graham K. Rogers


Terminal


Ever since the first Macs appeared, they have been known for the graphical user interface (GUI): icons instead of command line work which before the mid-1980s was the norm. Paradoxically, the arrival of OS X brought with it easy access to the command line should users ever want this, although it is possible to use the computer without ever needing to work at the command line at all.


It is easy these days to quit a process in any operating system. In OS X this is done just by using the Command + Q key combination. Sometimes, however, the application itself may be locked up -- perhaps because of a file problem, or poor access to internet resources -- and some stronger action may be needed. In most cases, users may find that the Force Quit feature in the Apple menu (top left on the menu bar) will suffice.

The problem may lie not with one of the installed processes but another of the underlying utilities which will not be shown in the list when Force Quit is accessed. Users may need to open a utility (in Applications/Utilities) named Activity Monitor. It is here, for example, that I will come when the Flash Player installation is playing up and the Mac's fans are going wild. It is easy, by highlighting any recalcitrant entry, to quit that and restore peace.

Among the data displayed, this lists all the open processes and the resources used. For those not used to such displays, the names of some of the applications may appear strange. Some are helper processes that OS X (with its Unix underpinnings) needs to operate. As well as the Process Name, the first item shown is a PID or process identification number. It is this number that the system needs in order to make the process stop running.


With Terminal it is possible to retrieve the numbers and to stop processes with some basic commands, but as with all such process, if users are not sure, then Don't.


Identify

As with the Quit feature in Activity Monitor, it is necessary to identify the process before we can take action using either the kill or killall command. To make this identification we use ps but we need to specifiy parameters. With just ps, only the process being used is identified (the bash shell). To identify all processes being run by the user we use the -u switch, followed by the username (shortname). In my case, this is

ps -u graham


PID


A full list of all processes being used by the specified account is displayed. From the user account, I am also able to discover processes running in the Admin account, by entering that account name instead.

ps -u admin_name

The list starts with the User Identity (UID), followed by the Process identity (PID), the accumulated time (processes are not running continuously) and then the process and its location.


Kill by Number

Having identified a process we may stop that running by using the kill command. Again, I emphasise the need for care. This is usually done with processes that are specifically focussed on, such as one that the user might have running in Terminal (See Notes, below).

To illustrate how kill works, I started the app called DigitalColor Meter that is found in the Utilities folder of Applications. Using the ps command (above: ps -u graham) I identified the PID as 1880 and typed in the command,

kill 1880

The process was terminated.


Kill by Name

It may not always be easy for some users to go through the process of identifying a specific application and its PID to use kill. An alternative is to use killall with a specified name. To do this, I began by starting the utility called Grab and simply entering the command,

killall Grab

stopped the process.


Not all of the Mac's installed programs have such convenient short names and some like DigitalColor Meter have gaps, which would normally signal to Unix a separate part of a command structure. Being Unix, there is a way round this. To indicte a space, we use a slash \ and I again used the utility DigitalColor Meter to illustrate this, with the command,

killall DigitalColor\ Meter

which stopped the process.


Notes

Using such commands will terminate the application, even if there are processes taking place, so data may be lost if this is not done as a last resort. I chose the two utilities -- DigitalColor Meter and Grab -- precisely for this reason: there were no related processes or data that would be affected when quit in this way.


A useful page of information on the PID and how processes are dependent on each other, is available on the IBM DeveloperWorks pages in the Speaking Unix section (8).


In addition, a tips page on OS X Daily examines the use of the yes command (there really is such a command) to stress out the CPU and uses killall to terminate the four running versions of yes. As William Pearson writes here, unless there is a valid reason to run this . . . better not as it will cause performance issues.


To be continued. . . .



See Also -

  • New Users and Terminal (1) -- A Quick Look Round
  • New Users and Terminal (2) -- Basic Navigation
  • New Users and Terminal (3) -- Shell Basics
  • New Users and Terminal (4) -- Lists and Manuals
  • New Users and Terminal (5) -- Internet Use
  • New Users and Terminal (6) -- Questions of Identity
  • New Users and Terminal (7) -- A Little More Discovery
  • New Users and Terminal (8) -- File Commands and More
  • New Users and Terminal (10) -- Browsing the Web using Unix
  • New Users and Terminal (11) -- Unix Tricks from OS X Daily
  • New Users and Terminal (12) -- Installed Text Editors - emacs, nano, pico, vi and vim
  • New Users and Terminal (13) -- Installing and Using the Utility, WGET
  • New Users and Terminal (14) -- Passwords, Purging and Closing Notes
  • New Users and Terminal (15) -- Permissions and chmod


    Graham K. Rogers teaches at the Faculty of Engineering, Mahidol University in Thailand. He wrote in the Bangkok Post, Database supplement on IT subjects. For the last seven years of Database he wrote a column on Apple and Macs.


  • advertisement



    Google


    Made on Mac

    For further information, e-mail to

    information Tag information Tag

    Back to eXtensions
    Back to Home Page