Definition : Everything in Linux runs as a process, I mean everything, including services and a shell command that is running on a terminal. As a matter of fact, the opened terminal it’s self is a process. Therefore, a process in Linux is a running program. A process can either run as a shell, a job or in the background.
The command used to view all the current processes running on Linux system is “ps“, which means (print snapshot) of the current processes. ps will show the running process of the particular user, but of course you would need to pass the command with options many times.
ps -> Show current processes
ps L -> Show format specifiers
ps ef -> Show all Processes
ps aux -> Show all Processes
The “USER” field represents the user that is running the process
The “PID” field represents the process ID and it is unique.
The “%CPU” field represents the amount of the CPU the process is using in %
The “%MEM” represents the amount of the memory the process is using in %.
The “VSZ” field represents the virtual memory size. The virtual memory size is the memory size the process has reserved and has access to but not currently using it.
The “RSS” field represents the resident memory size or resident set size. The resident memory is the memory size that has been allocated to the process in RAM. (i.e, physical RAM size the process is using). The RSS field is also represented as “RES” if the top command is used.
The “TTY” field represents the terminal the process is running on. For a process that is running in the background, you will see “?” but for a process that is not running in the background, you will see the terminal, the terminal can be in the form of “pts/0”.
The “STAT” field represents current process states. The process states are as follow:
ps fax -> Show processes hierarchical relations.
ps fU <username> -> Shows current processes running by <username>.
ps eo
pid,ppid,user,cmd
-> Show processes with specific specifiers we pick.ps -f --forest -C <process_name> -> Show a process tree for a specific process <process_name>.
Consult man ps to learn about the alphabets representation of the process state.
ps -ef | grep <PID> -> to find the process name of the PID 36805.
pstree | grep httpd -> To see the tree of the httpd process.
ps -auxf | sort -nr -k 3 | head -10 -> View the top 10 CPU Consuming Process.
CPU :
some useful commands :
w <user_name> -> Learn about some user's head activity and what are they doing.
uptime -> to check how long the system has been running.
lscpu -> View different informations about your CPU architecture
Jobs :
A job cannot be made persistent after a reboot. It just runs on the Linux shell. but a job can be " suspended / stopped / continued ". here are some jobs that keep the shell busy for a while, thereby making the admin redundant until the job gets completed. The admin cannot continue their work except another terminal is opened. One of the Jobs that take a long time is using the dd utility to make a flash boo-table, especially an ISO that is about 8 GiB. I know how much time this will takes . Lemme make it clear for you, am going to run a dummy command using the dd utility.
you can see that the command keeps the shell busy and won’t release the cursor. As a user, you can make this kind of job run in the background so that you can continue to do other things.
ctrl + Z then bg -> to make the job run in the background.
command& -> add "&" in the end of your command to run it in the background.
jobs -> to display the running command in the background.
fg n -> to move the job to the foreground.
How to kill a process :
There are some situations where an application will stop responding and you may have done all the necessary things to stop and start the application but it never comes up because the real process is still running and was never stopped in the real sense, the only way to come out from such sometimes is to kill the process by sending a signal.
consult man 7 signal to learn about the different types of signals.
kill -9 <PID> -> to kill a process using<pid>.
pkill -9 <process_name> -> to kill a process by the process name.
killalll -9 <process_name> -> Same thing as ^.
=> once you kill the parent process is killed. the child process will DIEEEEE too.
Process Priority :
Every process, when they are started are assigned the same process priority. i.e, they run with almost the same amount of system resources except in a few cases. you can nice such process. i.e, give it a higher priority than other processes by assigning a higher amount of system resources to the process. More so, if a process is slow or taking time to complete, it could be a job as well, you can also re-nice the process. i.e, assign a higher amount of system resources to the process. Nicing and re-nicing a process, in other words, setting and resetting/changing the priority of a process is simply giving more CPU time to a process than the other and it can either be positive or negative => nice value ranges from -20 (highest priority) to +19 (lowest priority).
top -> display the top processes that are using more higher processing resources.
nice -n <nice_value> <command> -> to give a command a nice value before running it.
renice -n <nice_value> <pid> / -u <username> -> to give the process a new nice value. either with <pid> or the <username>. => Another way to renice : run the command "top" and then press on "r" button to renice a process, make sure to precise the pid.
Tuned:
As a system administrator, you can use the TuneD application to optimize the performance profile of your system for a variety of use cases.
yum -y install tuned
systemctl enable --now tuned
tuned-adm
ps -ef | grep <pid> -> to find a process name with process ID.
Otherwise, great job. lets move on to the next chapter.
Last updated