Multiple Threads execution & Process utilization

Multiple Threads execution & Process utilization

🚀Introduction

In modern computing, multithreading has become an indispensable technique for optimizing performance and responsiveness in software applications. Multithreading enables a program to perform multiple tasks concurrently, allowing it to take full advantage of multi-core processors and distributed computing environments.

📈Top Command

Apart from showing real-time resource utilization, the 'top' command provides various other information about the computer's performance that we haven't explored yet. Let's delve into its additional features and functionalities.

9.jpg

  • The first line shows the time from when the system is running no of users who is using your system in my case it is 1 and the load average on the system

  • The second line shows the number of tasks active out of which how much is running how much sleeping and whether is there any zombie process or not

  • The third line of the 'top' command indicates that the process is using 0.8 seconds of CPU time, which is not ideal. It also shows that the process is utilizing only 0.0 per cent of CPU time, which is not efficient. On the positive side, 98.8 per cent of the CPU time is idle, meaning the CPU is mostly waiting for interrupts. The 'hi' and 'si' values represent software and hardware interrupts, respectively.

Checking resource utilization

top -p PID

It will show the status of the process according to the pid entered in the image below it is showing the status of the pid 1 which is a root process

lsof

📂lsof(list of open files)

  • It will show the status of the open files currently in the system, along with the processes using those files

  • You can use various flags with it like -u and -p to find the process with a specific username and process id specifically

lsof -u shivansh

lsof -p 1

🧵Threads

  • It is an execution unit within a process, which has its stack as well as a set of registers.

For eg:- let's say I am writing this blog two tasks are happening simultaneously first is it is letting me write the code and save it at the same time so two threads are running currently one is writing the code and the another is saving

ps m

  • This command is used to check the process running and the associated threads with it. Threads will be shown with empty pid

pts/0 is the process and the process below the pts/0 is the thread of that process

⏳Uptime

  • It will show the system's uptime or the time the system has been running it will show first the current time according to the system and then days,hrs: minutes, and number of users and then load average
uptime

it will show the time of the system and it is up from 7 hrs and 14 minutes and number of user which is 1 in my case and then load average shows the average load over 5,10,15 mins

💾vmstat

  • It provides information about the process, memory, paging, and block I/O. It is commonly used to troubleshoot performance issues and monitor the overall health of the system.

  • procs: It shows the number of processes waiting for the runtime (r) and the processes that are in uninterruptible sleep (b).

  • memory: It contains information about memory usage. It shows the swap space used (swpd), free memory available in the system, and the memory used for cache (buff) and buffer (cache).

  • swap: It contains information about the system's swap space. The "si" value shows the memory that has been swapped in from the disk, and the "so" value shows the system memory that has been swapped out to the disk.

  • io: It provides information about the input/output activity in the system. The "bi" value shows the number of blocks received from a block device, and the "bo" value shows the number of blocks sent to a block device.

  • System: It provides information about the system as a whole. "in" shows the number of interrupts per second, whereas "cs" shows the number of context switches per second.

  • cpu: It provides information about CPU utilization. The "us" (user time) represents the time spent by the CPU running non-kernel code, while "sy" (system time) represents the time spent by the CPU running kernel code. "id" shows the percentage of time the CPU was idle, "wa" shows the percentage of time the CPU was waiting for input/output requests to be fulfilled, and "st" shows the percentage of time stolen from the virtual machine (in virtualized environments).Logging

  • It is a process in which the system maintains a record about the events happening in the system. It is an important tool for troubleshooting and debugging, as well as tracking the activities of the system.

  • The files that store these events are called logs, and they are present in the /var directory, which is the location for variable data in the system.

📝Syslog

  • The process of logging collects information about various events happening in the system, such as system activities, errors, warnings, and user actions. This information is then sent to the system logger, which is responsible for recording and managing these logs. The system logger stores the collected data in log files in the designated directory (e.g., /var/log/) for later analysis, troubleshooting, monitoring, and auditing purposes.

  • Syslogd is a daemon for the syslog, which patiently waits for processes to generate log messages. As soon as an event occurs, it springs into action, deciding what action to take with the log message. It may choose to output the message to the console or save it to a log file.

cat /var/log/syslog

  • to see all the log files in your system
ls /etc/rsyslog.d
  • To send the manual message to the log file user this command
logger -s "message"

In my case, I have written Shivansh in place of the message so it shows the message as Shivansh

All log files are present in /var/log/ directory go to that directory and you can see all the log files which the system has

📝🔍Ways through which you can log message

  • Syslog:- Standard logging facility provided by the operating system to log a message using the syslog command in your shell

  • Logging:linux- command line utility which gives the facility to send the message to the Syslog

  • Logrotate:- utility to compress and delete old log files, it is typically configured to run automatically, It runs every day through a utility known as crowns

ls /etc/logrotate.d

it will show you all the config files which maintain the log files for different application running

  • Custom logging solution:-You can also use other logging solution such as rsyslog,syslog-ng which is more feature rich than these files

End of Linux blog

This will be the end of our Linux blog next we will be learning about Git and GitHub and its various command using which you can work with the Git and GitHub without any hesitation