Linux Fundamentals 6: Processes and Services

Process's are programs running on the machine and are managed by the kernel. To view the currently running process's we have several options.

ps aux

We can also monitor process's using the top command

top

We can also use glances (you may need to install this).

glances

The most important part is the PID, this is the unique id of the process. This can be used to terminate the process.

The process with PID 1 is the root of all process's and is created by the kernel when the system starts. If this is terminated the operating system will shut down.  All other process's are spawned from the this one process.

Kill

To kill a process you can use the kill command.

kill <processId>

You can also pass signals the command

kill <signal> <processId>

T0 view the signals available you can use

kill -l

Your command with a signal will look like this.

kill -9 1222

Services

A service can be made up of several processes, an example is httpd, a service usually starts when the system boots.

To view running services you can use the below command

sudo systemctl list-unit-files

Start a Service

sudo systemctl start <name>


Stop a Service

sudo systemctl stop  <name>


View Status

sudo systemctl status <name>

SystemD

At a very high level systemd is a service manager that runs as PID 1, it allows us to start services when the system boots.

Typically we would have a .service file and a service unit file, a service unit file looks similar to the following.

Setting this up will allow you to control you service using the systemctl command detailed previously.

We will look into this further in a  later blog post.