Managing Packages and processes in Linux - Day 2

At this point, we have learnt about a lot of things including how to manage users, groups and also we saw a lot of commands that are present in Linux. But what happens when we want to download something in Linux. Let’s start our discussion with that
Package Managers
As we all know package managers are programs that help you to manage packages. In linux, to download and use programs, there are primary 2 kind of package managers. One being dpkg and the other being apt. I’ll not waste your time and I’ll just give you a quick overview of these and also write out some important things about these 2
dpkg
This is the low level package manager that helps install packages after you download a .deb or .rpm file in your linux distro. Based on your distro you’ll download either .deb or .rpm.
This package manager is pretty dumb. Let’s say you download a .deb file but there are dependencies in that package, then you’ll have to manually download those dependencies at first and then you can download your application
So, most of the times, we tend to use the other package manager
apt
This is a high level package manager in your linux distro which is not dumb as dpkg. The main problem in dpkg was that you had to manually install the dependencies. But the case of apt is different. If your package has dependencies, it will automatically download it for you thus saving you a lot of time
Installing a package is very simple in this. Just type:
sudo apt install <package-name>
To see your installed packages, you can use this command:
sudo apt list --installed
To remove a command, you can use these commands
sudo apt remove <packagename> # doesn't erase user data and removes application
sudo apt remove <packagename> # removes the applicatio and also user data
Updating and Upgrading
The apt comes with utility commands for both updating and upgrading commands. The two commands being:
sudo apt update
sudo apt upgrade
The sudo apt update command fetches the latest information about available packages from the configured repositories. It essentially tells your system to check for any new or updated software packages that are available for installation or upgrade.
After running sudo apt update, the sudo apt upgrade command downloads and installs the newest versions of the software packages that are already installed on your system. It will only upgrade packages that have newer versions available.
You should use both commands together to ensure that your system is running the latest software and security patches. Running sudo apt update first is crucial because it provides the package manager with the latest information about available updates. Without it, sudo apt upgrade wouldn't be aware of the newest versions and might not install them
snap
Snap is another package manager which are used to download standalone applications which don’t normally interact with other processes. The applications installed using snap are installed in form of containers i.e they are installed in isolated environments with dependencies packaged at once
Normally it is used to download applications e.g vscode
Snap is being managed by a daemon named snapd. If you don’t have snap installed you can easily install it using:
sudo apt install snapd
Processes in Linux
To give you a simple overview processes are instances of running program. To see the processes running in your system, you can use this command
ps aux
Also you can use this command to see processes with realtime usage of CPU, MEMORY:
top # or
htop
You’ll be able to see all the processes that are currently running in your system
If you have vscode installed in your Linux system, do this experiment:
Open vscode once and then run this:
ps aux | grep codeClose it and again run the same command
You’ll be able to understand that this returns the currently active processes. The grep part helps to sort out the processed based on the search term you provide
The processes that we open by ourself are known as interactive processes i.e we have to open then only the processes open
When you ran ps aux command, you were able to see a long list of processes. But you didn’t start them right? You will not be able to recognize most of those commands. So who started it?
Daemons
Well, those are system processes that start when your pc boots up. Those are known as daemons. Basically daemons are background processes that we don’t start, it starts at boot time automatically
These are also referred to as systemd units
Systemd
I did talk about what systemd on day 0. But here’s are some points that will give you the idea of what systemd is:
The master daemon which looks after all the daemons
This is also known as the service manager or the process manager
The init system that I talked about in day 0
Responsible for mounting fs, starting all services
Basically this is the 1st process after the boot cycle in your pc. To see a tree of processes that have ran when your system completed the boot lifecycle, you can use the command:
pstree
You’ll be able to see that the 1st and the topmost process of the tree is systemd
systemctl
This is the systemd utility that helps us to control all our daemons. With the systemctl command, you can start messing up with your background processes. Here are some commands that you can refer to get started:
sudo systemctl start <service>
sudo systemctl stop <service>
sudo systemctl restart <service>
To control weather a service will start at the system start or not, you can use the enable or disable command of systemctl:
sudo systemctl enable <service> # Enables a service at system reboot. Basically tells the pc that the service should start automatically when the pc boots up
sudo systemctl disable <service> # self explanatory
See list of active daemons
To check the list of active daemons, you can use this command:
sudo systemctl list-units
Here, you'll be able to see all kinds of processes including .devices, .services. To see only of type services:
sudo systemctl list-units -t service
Now you are well versed about how to inspect, check which processes are running. But what happens when you want to kill a running process?
kill
The kill command is used to kill a running process in linux. But to kill a process, you need to have a process id. But let me tell you one more command:
ps -u <username>
This command will list out all the processes which is running for a particular user
Now, let’s say you want to kill a process named “abc”. For that, you can use either of these 2 commands:
ps -u <userName> | grep <abc> # or
pgrep <abc> # only returns processid
Now once you have the process id, it is simple to kill a process with one command i.e:
kill <processId>
Conclusion
So, that it for today, I hope I was able to add some value to your life. Also with this article, hopefully we are done with linux as of now. Make sure to explore linux more and also a like and comment would really help me keep myself motivated in continuing this series. Thanks and see ya



