Process Management And Handling

Process Management And Handling

What happens when you run a program or an app in your system, the system assigns a unique digit to it. This is what is know as the PID of running process, running programs are known as process in a computer system and they are properly managed by the system for the user. PID a.k.a Process IDentifier is a unique identifier assigned to each running process in a system. In computer system, it can also be seen as the names of all the members of an extended family which is their unique identity whereby any member can be called by just mentioning the name(identity). You can also control and observe input and output in a computer system using the programs PID. PID control is a feedback mechanism used in systems to maintain desired output by continuously adjusting input based on error between desired and actual output.

USES OF PID

TechWhiz you said systems do maintain and manage each running process with it ID so why do we still have to manage it ourselves.

Yes! Whether or not you are a system engineer, it's a good thing to know how to handle the different processes that are carried out by your system.

  • You will be able to track and manage individual process

  • You can identify process that might use up system memory

  • As a system engineering, you can track and manage processes of other users of the system

PROCESSES

Now that we know the meaning of PID, how and where can we manage PID? Operating systems like Windows, GUI-based Linux etc. offer a cool setup where you can see the process and manage them, but there are certain limited to that, to properly handle this process let us head back to the traditional way - Command Line Interface(CLI). For this topic, our focus will be on Unix Systems.

A Short command for displaying all the processes is ps aux, this command gives us a detailed list of the current running processes. We can also get the process information in real-time just like our task manager with the command top

Lets briefly discuss each of the information displayed by ps aux

  • USER - This column is simply the user or account running a particular process at a time. The root user with /init ro command will always be running once the terminal is open.

  • PID - This is the Process ID as earlier discussed, with the Process ID we can determine the number of processes running in the system.

  • %CPU - This is a metric that indicates the percentage of the total processing capacity of a computer's CPU that a particular process is using.

    1. 0%CPU means that the process is not currently using the CPU, maybe in writing state or idle.

    2. 100%CPU means that the process is using the entire processing capacity of one CPU core without being constrained by other factors.

  • %MEM - Same as %CPU but indicates the total physical memory (RAM) usage of a process. It reflects the total amount of the system memory a process is consuming relative to the total available memory

    1. 0%MEM means that the process is not currently using any memory

    2. 100%MEM means that the process is using all the available physical memory

    3. 50%MEM means that the process in using half if the available physical memory.

%MEM metric helps users understand how memory intensive a specific process is and can identify process that might be consuming excessive memory resources.

  • VSZ - Virtual Memory Size, it represent the total virtual memory used by a process regardless of whether the memory is currently in RAM or swapped out to disk.

    VSZ includes all memory a process has requested both in RAM and out of disk. It represents the total virtual address space that the process can access. It is usually displayed in kilobytes(Kb) or megabytes(Mb) depending on the scale of the memory allocation. It is not a direct measure of actual usage but a measure of the total virtual memory space the process has reserved.

  • RSS - Resident Set Size, it represents the portion of a process's VSZ that is currently held in RAM and is actively used by the process. The units of RSS is kilobytes(Kb) or megabytes(Mb)

      if RSS < VSZ then the virtual memory may have been swapped out to disk
      if RSS is close to VSZ then the virtual memory allocated is residing in RAM
    
  • TTY - TeleTYpewriter, this refers to a terminal console. A terminal is a device/program that allows a user to interact with the computer by entering commands. In the case of PID, TTY is an indication of whether a process is associated with a terminal or not.

  • STAT - The STAT columnn represents the current process status at the moment the information is collected. It consists of several characters that represents the process state.

COMMANDS TO HAND PROCESS ID

The process ID of a program can be controlled by sending signals and simple commands to the system to handle the execution of the program. These commands include:

  • ps

  • kill

  • pgrep

  • pkill

  • exit

  • trap

ps - We have already seen in early study the power of the ps command which is used to list the processes that are currently running in the system.

kill - This command is used to kill a process i.e automatically stop a process that was running abruptly in the system. In a company setting, the command makes it easier for system admins to each and every process of users in the company, say a user mistakenly creates an infinite loop, this can be stopped with the kill command by the superuser.

pgrep - Just like the ps command, the command lists all process IDs but based on a specific pattern by the user. pgrep looks through the currently running processes and lists the process IDs which match the selection criteria to stdout. Signals can also be passed as options to the command.

pkill - Same as the kill command instead the process is killed based on the options and pattern specified by the user of the system.

exit - This is a powerful command used for process termination. The closes/terminates any normal process. When we launch a terminal, a process which is known as the parent process automatically start. After working with the terminal, typing exit will terminate the process and thereby close the terminal. A status code can also be passed to the command which also tells the system if a program ran successfully or not.

0 - successful

1-255 - not successful (failure)

trap - trap helps script end cleanly, whether the script was successful during execution or not. This can help users understand if a script was successful or not by watching for signals using the trap command.

You can understand more deeper concept of this commands by using man <command-name> in your terminal, this will display any information concerning the command you inputted.

If you like this, share and leave a comment below of what you think. ๐Ÿ˜Š๐Ÿ˜Š

ย