Process and Service in Linux¶
Process¶
- A
processin Linux is an instance of a running program. It is the basic unit of execution in Linux, and the Linux kernel manages multiple processes concurrently, giving the illusion of multitasking.
Key Characteristics:¶
PID: Each process is identified by a Process ID (PID), a unique number.Parent-Child Relationship: Processes have a hierarchical structure, where a process can spawn child processes.States: A process can be in one of several states, such asrunning,sleeping,stopped, orzombie.Environment: Each process operates within a specific environment that includes environment variables, acurrent directory, anduser permissions.
Working with Processes¶
Listing Processes: You can list processes using commands likepsandtop.ps: provides a snapshot of current processes.top: displays an ongoing update of processes and system resources.
Managing Processes: You can manage processes using commands such askill,nice, andrenice.killsends a signal to a process, typically to terminate it.niceandreniceadjust the priority of a process.
Service¶
- A service in Linux is a special type of background process that is started at boot time or on demand and performs a specific function or provides a particular functionality to other processes or users
Key Characteristics:¶
Daemon: Most services are implemented as daemons, background processes that are often started during the boot process.
Working with Services:¶
service [service name] start | stop | restart | statussystemctl start | stop | restart | status [service name]
- check all available services
/usr/lib/systemd/system
runlevel in linux¶
Linux systems typically define the following runlevels:
Runlevel workflow¶
Power on $\to$ BIOS $\to$ /boot $\to$ initprocess $\to$ runlevel
runlevel 1have root power, do not need root password to signin, but need physical signin
Check runlevel¶
vim /etc/inittab: this is the default runlevel
systemctl get-default: get current runlevelmulti-user.target: runlevel 3ctrl + alt + F3
graphical.target: runlevel 5ctrl + alt + F1
Change the current runlevel¶
systemctl set-default [Target runlevel].target
Set Boot Service and Firewall¶
- Check Services status
systemctl status [Services]
- Set to disable
systemctl disable [Services]
- Check all Services status
systemctl list-unit-files
Set firewall¶
- Check firewall status
systemctl status firewalldsystemctl stop firewalld: stop firewall service for this time
Power-off, Reboot and halt¶
sync: store data from memory to hard drivehalt: stop services and still power onpoweroffreboot: equal toshutdown -r now
In [ ]:
Copied!