Linux Process Management Tutorial For Developers

Linux is a multitasking system, which means it can run multiple tasks (process) at a time. Basically, a process is a running program or a task or a command on your Linux system.

Linux Process Management for Developers

When you are developing applications on Linux, you will be using a web server, database server etc..At times, you might want to have a look at the process or may want to terminate and restart it. In this article, we will cover some of the basic process related tips for developers working on Linux based systems.

Process Management Daemons

Every Linux system has one of the following process management daemons. It will be the first process to be started on the system when you boot it up.

1. Init – SysV (first adoption – historic)
2. Upstart – (first adoption – 2006)
3. Systemd (first adoption – 2011)

Note: In the latest OS releases, systemd is been widely used. in ubuntu 15.05, cenots 7, init is replaced by systemd.

Process related commands

You can list all the process in Linux using ps command.

To get a filtered meaningful output, you can use grep filtering utility. For example, if you want to list all the processes run by the vagrant user, you can execute the following command.

To get the process id  of a specific service, you can use pgrep with the service name as shown below.

To get the list of process in a tree structure, you can use the pstree command.

Note: pstree is not installed on Linux systems by default. You can install pstree from relevant distro repo.

To get the process id with the tree structure, use the -p flag.

If your system is little slow and if you want to get a dynamic view of processes, you can use the top command. Top updates itself in real-time based on the CPU and memory usage by the processes.

To terminate a running process, you can use kill and killall command.

If you know the process id, you can use the kill command as shown below.

To forcefully kill the process, you need to add -9 flag to the kill command.

If you know the name of the process, you can use the killall command.

Running Processes in Background

When you execute a command on a terminal, you will need to watch it executing until it finishes the execution. For longer running commands you actually run the process in the background.

To put a process in the background, just append the & at the end of the command.

For example, tail -f /var/log/syslog gives a dynamic view of log files when it is added subsequently. To put this execution in the background, you need to execute the command as shown below.

You can view the background jobs using jobs command.

For example,

In the above example [1] is the job id. To bring the job running at the background to foreground, use the fg command with the job id.

For example,

You can send the process to the background using the bg command. First, you need to suspend the process using ctrl+z.

For example,

If you going to run a really long running process, you can append nohup which stands for no hanging up. The advantage of using nohup over & is even if you close your terminal the process will run without interruption.

For example, let’s say you are untaring an archive which might take half an hour. In this case, you can use nohup and close the terminal. The job will run in the background without any problem.

Starting and Stopping Services

You can start, stop and restart services using the service command

Related

I am trying to create a volume in Glusterfs and  I am getting an error saying "Volume creation Failed:…

Read more

If you are running mission critical applications on servers, it is important to monitor and notify the administrators…

Read more
linux-finding-files

Note: In Linux, everything is treated as files. Even folders are treated as files. There will be situations where…

Read more

Internet is huge! Help us find great content

Newsletter

Never miss a thing! Sign up for our newsletter to stay updated.

About

The Best Tutorials & Tips to Speedup Your DevOps Workflow.

Created by Bibin Wilson.

​98
%

Off

Udemy Black Friday Offer Courses For $9.99 For Limited Time