Introduction to Linux process and daemons

What is a Linux process?

A Linux process is a program running in the Linux system. Depending on Linux distributions, it's also known as service. In Linux community however, a Linux process is called daemon.

When you start a program or running an application in Linux, you actually execute that program. A Linux process (a daemon), running in foreground or in the background, uses memory and CPU resources. That's why we need to manage Linux process. Keeping unused Linux process running in the system is a waste and also expose your system to security threat.

We are going to learn and practice Linux process management using Linux ps command, pstree command and top command in this tutorial.

Linux process management

In Linux, every running process or daemon is given an identity number called PID (Process ID). The process id is unique. We can terminate unused program in the system by stopping its process id.

In order to manage Linux processes, we need to identify some process information such as who's responsible for the process, which terminal the process is running from and what command used to run the process.

We can view a particular Linux process by providing its characteristic. A Linux command which can be used to check the ID of a running process in Linux system is the ps command.

Linux ps command

Linux ps command reports a snapshot of the current processes.

[email protected]:~# ps
353 tty1 00:00:01 bash
736 tty1 00:00:00 ps
[email protected]:~#


This version of ps accepts several kinds of options:
1) UNIX options, which may be grouped and must be preceeded by a dash.
2) BSD options, which may be grouped and must not be used with a dash.
3) GNU long options, which are preceeded by two dashes.

Here are more examples from the ps command manual page:

To see every process on the system using standard syntax:
ps -e
ps -ef
ps -eF
ps -ely

To see every process on the system using BSD syntax:
ps ax
ps axu

To print a process tree:
ps -ejH
ps axjf

To get info about threads:
ps -eLf
ps axms

To get security info:
ps -eo euser,ruser,suser,fuser,f,comm,label
ps axZ
ps -eM

To see every process except those running as root
(real & effective ID)
ps -U root -u root -N

Because Linux is a multi-user, multitasking operating system, it can run many processes at a time. With multitasking system, multiple processes are allowed to operate simultaneously without interfering with each other, while a multi-user system allows multiple users to use the system simultaneously. If one process has problem and stops functioning, it will not affect another process because each process runs in its own protected memory space.

Linux pstree command

Other than Linux ps command, a pstree command can also be used to view a currently running process in the Linux system. Instead of viewing details in list, pstree command displays a process in a tree diagram.

Let’s practice some Linux pstree command examples. Login as a normal user and from the command line, type 'pstree' and press Enter:

[email protected]:~# pstree
[email protected]:~#

You should get a result similar like this. At the top of the result is a process called init. The init is process control initialization. It is loaded first during the boot up process and remain in the system.

There are some options that you can use with Linux pstree command. Below is the pstree synopsis taken from the pstree info page; :

pstree [-a] [-c] [-h|-Hpid] [-l] [-n] [-p] [-u] [-G|-U] [pid|user]
pstree -V

The command pstree with -a option will show command line argument:

[email protected]:~# pstree -a
|-agetty 38400 tty2 linux
|-agetty 38400 tty3 linux
|-agetty 38400 tty4 linux
|-agetty 38400 tty5 linux
|-agetty 38400 tty6 linux
|-atd -b 15 -l 1
| `-pstree -a
|-crond -l10
|-klogd -c 3 -x
[email protected]:~#

The command pstree -p will show PID after process name:

[email protected]:~# pstree -p
[email protected]:~#

The pstree command also support pipe. You can use pipe and less command to scroll a large output:

[email protected]:~# pstree -np | less

Linux top command

You can also view a dynamic real-time of a running process with command top. This is an example when you run top command:

top - 14:11:02 up 1:56, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 25 total, 1 running, 24 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0% user, 0.3% system, 0.0% nice, 99.7% idle
Mem: 126500k total, 57148k used, 69352k free, 5280k buffers
Swap: 497972k total, 0k used, 497972k free, 42888k cached

499 bill 16 0 1024 1024 824 R 0.3 0.8 0:00.08 top
1 root 9 0 228 228 200 S 0.0 0.2 0:04.42 init
2 root 9 0 0 0 0 S 0.0 0.0 0:00.06 keventd
3 root 19 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd_CPU0
4 root 9 0 0 0 0 S 0.0 0.0 0:00.00 kswapd
5 root 9 0 0 0 0 S 0.0 0.0 0:00.00 bdflush
6 root 9 0 0 0 0 S 0.0 0.0 0:00.11 kupdated
10 root -1 -20 0 0 0 S 0.0 0.0 0:00.00 mdrecoveryd
11 root 9 0 0 0 0 S 0.0 0.0 0:00.21 kjournald
60 root 9 0 592 592 516 S 0.0 0.5 0:00.14 syslogd
63 root 9 0 448 448 396 S 0.0 0.4 0:00.03 klogd
115 root 9 0 304 304 264 S 0.0 0.2 0:00.02 udevd
296 root 9 0 0 0 0 S 0.0 0.0 0:00.00 khubd
321 root 9 0 512 512 460 S 0.0 0.4 0:00.03 inetd
325 root 9 0 1516 1516 1260 S 0.0 1.2 0:00.09 sshd
336 root 8 0 620 620 536 S 0.0 0.5 0:00.04 crond
338 daemon 9 0 664 664 576 S 0.0 0.5 0:00.00 atd

That's some basic information about Linux process. Linux process is a very important topic and plays important role in Linux system. In the Stop and terminate hang program in Linux tutorial, you can see a real situation how ps command can be very useful in Linux administration task.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.