GNU/Linux Bash Commands for Beginners -4 Manage and Monitor Process Commands

Hi,

I will explain how to Manage and Monitor Process Commands in this tutorial series.

 

Read previous article before this.

https://ittutorial.org/linux-commands-tutorial-for-beginners-3-system-statistic-commands/

 

Manage and Monitor Process Commands

Before explaining Linux Process management and monitor commands, let’s look what is the Process concept.

Process: The name given to each part of the programs running on the operating systems. Processes hold code of the program that is currently running and the functions it performs.

In general, Processes contain the following structures.

 

  • Running Program
  • Asynchronous function related with Program
  • A task specified by the processor

 

The commands in Linux that are related to the Processes or that monitor and management of the Processes are as follows.

 

 

  • ps
  • kill
  • killall
  • bg
  • fg
  • pidof
  • pgrep
  • pstree
  • fork
  • getpid
  • getppid
  • exec
  • pipe

 

Before explain the process management commands, I want to remind you again and again an important command. This is the “man” command. With this command, you can learn the commands that you hear but want to learn in detail.

It provides the user with detailed information about the functions of the command and the parameters it receives when used with these parameters.

 

Now, as an example, we refer to our man command to learn “lastcomm”. Its usage and output are as follows.

 

 

ps command

With this command, all processes running on the Operating system and process ids of these processes are displayed to the user.

Use and output of the command are as follows.

 

You can use ” -ef ” option with this command to see details of processes.

[root@MehmetSalih ~]# 
[root@MehmetSalih ~]# ps
  PID TTY          TIME CMD
27473 pts/3    00:00:00 bash
27711 pts/3    00:00:00 ps
[root@MehmetSalih ~]# 
[root@MehmetSalih ~]# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Sep24 ?        00:00:01 /sbin/init
root         2     0  0 Sep24 ?        00:00:01 [kthreadd]
root         3     2  0 Sep24 ?        00:00:00 [ksoftirqd/0]
root         5     2  0 Sep24 ?        00:00:00 [kworker/0:0H]
root         6     2  0 Sep24 ?        00:00:00 [kworker/u:0]
root         7     2  0 Sep24 ?        00:00:00 [kworker/u:0H]
root         8     2  0 Sep24 ?        00:00:00 [migration/0]
root         9     2  0 Sep24 ?        00:00:00 [rcu_bh]
root        10     2  0 Sep24 ?        00:00:34 [rcu_sched]
root        11     2  0 Sep24 ?        00:00:00 [watchdog/0]
..............
..............
[root@MehmetSalih ~]#

 

 

 

kill command 

With this command, a process can be terminated by typing the ids of the existing processes in the operating system. In Linux systems, only the priviliged user like Root who has the privilige on that process can kill it.

 

root     16200     2  0 Sep24 ?        00:00:02 [kworker/5:2]
oracle   16569 11394  0 Sep24 pts/1    00:00:00 sqlplus   as sysdba
oracle   16572 16569  0 Sep24 ?        00:00:00 oracleDeveci (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
root     16961     2  0 Sep24 ?        00:00:00 [kworker/11:1]
root     18422     2  0 Sep24 ?        00:00:00 [kworker/3:2]
root     18973     2  0 09:45 ?        00:00:00 [kworker/7:2]
root     20963     2  0 10:00 ?        00:00:00 [kworker/2:2]
root     21978     2  0 10:04 ?        00:00:00 [kworker/14:2]
root     22687     2  0 10:10 ?        00:00:00 [kworker/15:2]
postfix  25510  8689  0 10:28 ?        00:00:00 pickup -l -t fifo -u
root     26222     2  0 00:40 ?        00:00:00 [kworker/1:0]
root     26485     2  0 10:32 ?        00:00:00 [kworker/13:1]
root     26585     2  0 10:33 ?        00:00:00 [kworker/12:0]
root     27230     2  0 10:38 ?        00:00:00 [kworker/12:2]
root     27308     2  0 10:39 ?        00:00:00 [kworker/13:0]
root     27468  8598  0 10:40 ?        00:00:00 sshd: root@pts/3 
root     27473 27468  0 10:40 pts/3    00:00:00 -bash
root     27545     2  0 10:40 ?        00:00:00 [kworker/14:0]
oracle   27692     1  0 10:42 ?        00:00:00 oracle+ASM_pr00_Deveci (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
root     27716 27473  0 10:42 pts/3    00:00:00 ps -ef
[root@MehmetSalih ~]# 
[root@MehmetSalih ~]# 
[root@MehmetSalih ~]# kill -9 16569
[root@MehmetSalih ~]#

 

 

killall command 

This command terminates all processes of any programs whose names are provided to it as arguments (i.e., inputs).

killall [options] program_name(s)

 

For example: You want to kill all processes of java,apache or Oracle user, you can use following command.

 

 [root@MehmetSalih ~]# killall -9 java


 [root@MehmetSalih ~]# killall -9 apache


 [root@MehmetSalih ~]# killall -9 oracle

 

 

bg ( back ground ) command

This command may not be available on all Linux distributions. This command  resumes any stopped process in the background

It also lists the tasks currently running on the system.

For example, I will trigger and run any process, then i will stop it manually and will run bg command to resume this process in the background.

[oracle@MehmetSalih ~]$ bg
-bash: bg: current: no such job
[oracle@MehmetSalih ~]$ 
[oracle@MehmetSalih ~]$ crontab -l
00 02 * * * sh /home/oracle/scripts/full_backup.sh
[oracle@MehmetSalih ~]$ 
[oracle@MehmetSalih ~]$ 
[oracle@MehmetSalih ~]$ sh /home/oracle/scripts/full_backup.sh

Recovery Manager: Release 12.1.0.2.0 - Production on Wed Sep 25 11:18:58 2019

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

connected to target database: Deveci (DBID=152543005, not open)

RMAN> run{
2> ALLOCATE CHANNEL CH1 DEVICE TYPE DISK;
3> delete noprompt archivelog all completed before 'sysdate-4';
4> crosscheck backup;
5> delete expired backup;
6> RELEASE CHANNEL CH1;
7> }
8> 
using target database control file instead of recovery catalog
^Z
[1]+  Stopped                 sh /home/oracle/scripts/full_backup.sh
[oracle@MehmetSalih ~]$ allocated channel: CH1
channel CH1: SID=290 device type=DISK


[oracle@MehmetSalih ~]$ bg
[1]+ sh /home/oracle/scripts/full_backup.sh &
[oracle@MehmetSalih ~]$ 
[oracle@MehmetSalih ~]$

 

fg command

This command allows a background process to run in the foreground.

Now I will use fg command for above example like following.

 

[oracle@MehmetSalih ~]$ bg
[1]+ sh /home/oracle/scripts/full_backup.sh &
[oracle@MehmetSalih ~]$ 
[oracle@MehmetSalih ~]$ 
[oracle@MehmetSalih ~]$ fg
sh /home/oracle/scripts/full_backup.sh
specification does not match any backup in the repository


specification does not match any backup in the repository

released channel: CH1

Recovery Manager complete.
[oracle@MehmetSalih ~]$ 
[oracle@MehmetSalih ~]$

 

 

pidof command

This command displays the process id of a program on the operating system.

[root@MehmetSalih ~]# pidof init
1
[root@MehmetSalih ~]# 
[root@MehmetSalih ~]# 
[root@MehmetSalih ~]# pidof firefox

63
[root@MehmetSalih ~]#

 

 

pgrep command

With this command, the id of a currently running process is displayed to the user.

The usage of the command is as follows.

 

 

 

pstree command

This command displays the processes running on the system to the user as a tree.

Use of the command is as follows.

 

 

fork command

This is the command that creates a child process running on linux and unix systems. After the process is copied, there are two processes, parent-child in the operating system. This command is usually used to perform a different function on the operating system. Thus, the child process created with this command can see different functions on the operating system.

 

getpid command

This command displays the user id of the current running process.

 

getppid command

This command gives the user parent id of the current running process.

 

exec command 

This command allows a process to continue as a different program on linux systems. After this process, the process id and control block do not change. The Exec command works in 6 different ways depending on the parameters it receives and the functions it sees. These and the parameters they get are as follows.

 

int execl(const char *path, const char *arg0, ... /*,(char *) 0 */);

int execv(const char *path, char *const argv[]);

int execle(const char *path, const char *arg0, ... /*, (char *) 0, char *const envp[] */);

int execve(const char *path, char *const argv[], char *const envp[]);

int execlp(const char * file, const char *arg0, ... /*, (char *) 0 */);

int execvp(const char *file, char *const argv[]);

 

 

 

pipe | command

With this command, you can use any command’s output as input to another command. The “|” sign is used for this.

Use and output of the command are as follows.

 

Now output of ps -ef command will be used by grep command. After that output of grep command will be used by wc command.

[root@MehmetSalih ~]# 
[root@MehmetSalih ~]# ps -ef | grep smon
root 5804 27473 0 11:45 pts/3 00:00:00 grep smon
oracle 11132 1 0 Sep24 ? 00:00:01 asm_smon_+ASM
oracle 11317 1 0 Sep24 ? 00:00:00 ora_smon_DEVECI
[root@MehmetSalih ~]# 
[root@MehmetSalih ~]# 

[root@MehmetSalih ~]# ps -ef | grep smon | wc
3 25 182
[root@MehmetSalih ~]#

 

 

I will continue to explain Linux command tutorials in the next article.

  

Do you want to learn Linux System Administration for Beginners, then read the following articles.

GNU/Linux Administration Tutorial For Beginners

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

Leave a Reply

Your email address will not be published. Required fields are marked *