What's the best Linux OS for your enterprise data center?
A comprehensive collection of articles, videos and more, hand-picked by our editors
If you're a Windows admin taking on some Linux servers, you'll need to learn some basic Linux commands for process...
management. No matter which flavor of Linux you're using, all services are offered by your server as processes.
The very first task a Linux administrator should be interested in is process management. Start by getting an overview of what your server is doing; the ps command calls up a list of all currently running processes. From a root terminal, make sure a shell is started and you have logged in as root. You can do that either by typing the user name root and the associated password at the login prompt, or by logging in with your normal user account and using the command sudo su to open a root shell.
Normally the list of processes that ps discovers will be very short, as it only shows the processes that you've started from the current shell (see Figure 1). Many more processes, by default, are active on your server, and you can get a list with the ps aux command. On a typical server that isn't doing anything special, expect to see 150 processes or more.
Linux administrators often want to know if a specific process is running. Rather than browsing the list of active processes, you can use Linux pipes -- or program redirects -- and the versatile grep command-line utility. Using piping, you can send the output of one command to the command after the pipe: That will treat the output of the first command as input. You also can use the grep utility in a pipe to search lines that contain a specific string of characters. For example, to find out if your Web server is currently running, you would look for lines containing the text httpd, using the command ps aux | grep httpd. The ps part of the command generates a list of all processes currently running, which the grep utility filters to show only lines containing the text httpd (see Figure 3).
If the process you need is not running, you can start it manually. On most Linux servers, the directory /etc/init.d contains a list of scripts that you can use to start services: use cd /etc/init.d to access the directory and type ls to show the list of services on your server (see Figure 4). While this procedure will work for the majority of Linux servers, the latest Linux distributions may use a different procedure.
Often the names of the service scripts make sense; for example, the httpd process is started by the httpd service script (see Figure 4). Once you find the name of the service script you need from the list of files in the directory /etc/init.d, you can use the service command to start it. In this example, the command would read service httpd start.
The service command can be used for other purposes as well. You can use it to restart a service, or request current status information. To find out if your httpd service -- or any other Linux process -- is currently running, you can use service httpd status. If it is running and you need to restart it, you can use service httpd restart.
Always type the exit command to close your root shell; you should never walk away from a server that has an open root shell.
Now you're capable of performing some basic Linux service administration tasks, and can move on to Linux files.
Sander van Vugt is an independent trainer and consultant based in the Netherlands. He is an expert in Linux high availability, virtualization and performance. He has authored many books on Linux topics, including Beginning the Linux Command Line, Beginning Ubuntu LTS Server Administration and Pro Ubuntu Server Administration.