Processes, Services, & Daemons
Published: 2023-07-23 05:38:25

**<u>All process by all users :</u>**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9r50a5lqlp7wbdgc4a6l.png)

**ps aux | less**

VSZ : Virtual Memory Size in KB
RSS : Resident Set Size ( physical Memory , not swapped )
TTY : Started in Background NOT in Terminal if it as '?'
STAT :  State of the running process
TTY  :  Terminal 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f9t3gg14e64ofkqi1x14.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g0lv7ho9vikw7mwjxkb0.png)

This above command will remove or filter with -v or It won't appear in the screen.

Below is the Tree , how the process started one by one,

**pstree | less**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qll8aiyxqnz4k45i8jn6.png)

**ps aux | sort -nk 4 | tail -3**

( Here sort by fourth column i.e., Memory and tail 3 is the last three value which is consuming more memory )

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p1pw7kki91hnmq8k2az9.png)

Only giving 'ps' will show the process which are running in this terminal alone,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4ij4cbanpym22ib2td5.png)

aux --> will provide all process in all terminal.

**_<u>Monitoring :</u>_**

1. ps
2. ps aux | grep syslogs
3. top

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l54f4gilgtxqez7gv5oa.png)

PR : Priority 

Once you press 'd' then it will prompt for entering the number. Now we can change from 3 secs delay to 1 secs delay also like below ,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8wbopat1fzca37agleua.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b4tcivdvh9fbm1asljfv.png)

Press 'f' , it will show the abbreviation of the given name which shows n 'top' command.

F for select
Space-Bar for deselect the column
Q to go-back
S for which column you need to sort

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s5gy9ez8ufb83f0zvhnh.png)

Top command to batch file ,

top -n 5 -b > /tmp/top_output.txt ( 5 is the Iteration & out to a file )

**<u>Killing a process :</u>**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2hx1pvqi6ys5wmok9cf.png)

& - will send it to run at the back-end.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kl8p6gflifswqavsn8xw.png)

15 - Graceful shutdown
9  - Forceful

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8hcv8huqgew4p88cls6a.png)

NO SIGNAL - it saves and gets terminated
-9        - its killed

We should send only PID ? we can also send process name.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gvethhf8x9boi8282pfc.png)

**pgrep** --> greps the process id

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0xmtqjb36irk9xwa7ku4.png)

**kill -1 cmd &** --> even if you close the terminal , this killing process will run at the back-end.

**<u>PROCESS PRIORITY :</u>**

1. Focus on 6th column , nice value.
2. This is the priority value given to any process accordingly. 
3. You can reassign the priority or assign while start of the process itself.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dzt9a4z9g2on2xjxsucx.png)

**<u>Where these PID is stored ?
</u>**

1. /proc/<pid>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/171r53h5hmntzeir9uor.png)

**<u>Process Information :</u>**

cat /proc/cpuinfo

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tgowy8lzeylqv7wj90ti.png)

**<u>File System :</u>**

df -h ( h human readable )
watch -n 5 df -h ( for every 5 secs watch the df -h )

Logs :

1. tail is see the last lines in a file or log.
2. '-f' is used to check the real time logs.
3. /var/log --> system logs

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l50gxqplmt0b2ghe38ps.png)

If you want to check process which are running by specific user in TOP ,

top -u <user_name>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/up56cxonyle7bqyefopa.png)

In the below you can see , no terminal information.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2t6znxkgchih4zy48fwo.png)

But here you can see terminal information , but editing the TOP command like F , SPACE-BAR , S & Q

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yv7pd70fo7694jgh61a5.png)

If you want to check only one PID , 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5ask4ctqzs9qhscgbfl.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqf7583we9t4cr0loqmp.png)

**<u>STARTING & STOPPING OF SERVICES :
</u>**

1. In TOP command , you can see TTY as '?' , that means these process are started by Operating SYSTEM not manually.
2. systemctl and service commands are used , which is discussed in detail in other blog.
3. systemctl list-unit-files --type service | less
4. Static means ONLY ONE TIME WHEN NEEDED.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pkjsuo2x4o5xafu0gjqp.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c99ht40nd6l59baizwev.png)

**<u>What is SYSTEMD ?
</u>**

All system dot files will be here , which is used to run the daemon.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s4mki80b4ne5b3ko1mb8.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/enhuskrjugtkw67ehzt6.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wg83dyelr23pkeos8qgd.png)

System files are present here also,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2s9gbn98l3todputbf2v.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/46ubkpyxvbzsyc0shhb5.png)

**systemctl list-unit-files --type service --all | less
**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c0ftj2nsqz0wbqcemj7d.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t95u6wny6r0xfpmgtjy9.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ug53tc9y39ffuqwp56m.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6d6k2c3bd9icc1pc2tb6.png)

This is the list of services which are managed by " SYSTEMD ".

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f2sqh1isyzpbuwuv2ly5.png)

There are 3 section if you notice , **UNIT** - it will say the dependencies , **SERVICE** - service level information & **WANTED** - Environmental files .

The environmental file contains the , details of the environmental details of the specific service.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8iv837ap95ln3gaidr2y.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t3ykqbjfd2kwujnujpq0.png)

These are the service which are managed by SYSTEMD,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t0pe5jg02he9zn0gcbkw.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g5oyypo0sqehyo9zgjz9.png)

SYSTEMD can manage all CHILD process also ,

**systemctl list-unit-files | less**
proc-sys-fs-binfmt_misc.**automount**
dev-hugepages.**mount**

These type of extension is also maintained by SYSTEMD.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/78znbaurjd0npqb6qkx6.png)

Lets displace the dependencies of services ,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vyyaviv5y2aip1q9bh8h.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5bsvf7eahewsnd5kc84y.png)

All the immediate dependencies are listed.

**<u>RUNLEVEL :
</u>**

Now its called TARGETS. (TBD)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v301uyqezxnwbk4pg7ls.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/up2cyh0rt5em3t5arkz5.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/64zbtasmzcb6r5r8p2h4.png)

Also SYSTEMD can used in LOGGING, these are called JOURNALS.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wu82j14bdkzzjs8bbmks.png)

Some text will be RED colour , that means it as some issue.

Latest logs,


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pwupjmqz7qcqqr02psgg.png)

Real time logs ,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6gf5gvxj93uag8atvdwb.png)

Logs of Current BOOT session,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lqz3x2pm4b9f7j2ego1i.png)






















**<u>Note :</u>**

1. syslog - which is logged when the server starts , all starting logs will be stored here.

**ps aux | grep syslog**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ellc0zy2vx1kdet6qhdd.png)

2. Zombie task - Which didn't shutdown properly.
3. SIGNAL 15 is the default killing process. ( graceful shutdown )
4. Here in Linux , services are called daemon.
5. If you are creating a service to be started at the time BOOTING , then a symbolic link will be created.
6. Script10 service ( this can be used to replace the CRON Jobs ) which is by SYSTEMD
7. Mask - it will make a symbolic link to null and never can be started.