Processes System tasks Campus-Booster ID : **XXXXX www.supinfo.com Copyright SUPINFO. All rights reserved
Processes Your trainer Presenter s Name Title: **Enter title or job role. Accomplishments: **What makes the presenter qualified to present this course. Education: **List degrees if important. Publications: **Writings by the presenter on the subject of the course or presentation. Contact: **Campus-Booster ID: presenter@supinfo.com
Processes Course objectives By completing this course, you will: n Explain the process concept. And different types. n List and sort running processes. Using several tools. n Spot CPU hogs. Who s eating all the system power? n Use signals. To terminate and communicate with processes.
Processes Course topics Course s plan: n Processes on Unices. What s a process? n Running processes. Background, foreground and priority. n Listing processes. Unix tasks managers. n Signals. Primitive IPC.
Processes Processes on Unices What s a process?
Processes on Unices Processes Everything is a file, if not, then, it s a process. Unknown source
Processes on Unices Processes What s a process? n System task management abstraction n In-memory executable code n Many properties n Runs as a (uig,gid) couple n Attached to a tty n daemons n Identified by a PID
Processes on Unices Process Hierarchy A process can spawn other processes: init ftpd login init is the first userland process (PID 1) started off by the kernel. It s the ancestor of every processes. ls bash cp
Processes on Unices Process Hierarchy Processes on Unix: fork(). n Process can spawn children n Child process n Inherit environment n Die if parent die n Can be detached n Parent process n Must wait for children n Zombies
Processes on Unices Daemons Processes gone rogue. n Special state n Detached from original parent n PPID = 1 n No control TTY n STDIN n STDOUT n STDERR n Used for services
Processes on Unices Process State A process can be: Name Description Running Has CPU time Runnable Sleeping Zombie/ Defunct Waits for CPU time Does nothing / Waits for something (I/O, ) Process ended. Parent didn t wait() (yet)
Processes on Unices Zombies / Defunct processes Can t kill what s already dead. n Ended process n No CPU cycles n No resources n Only id block and process table entry n Needs to be wait() ed n Stalled parent n Bugged parent n Kill the parent
Processes on Unices Stop-and-think Do you have any questions?
Processes on Unices Stop-and-think The only way to get rid of zombies/defunct processes is to reboot the system. True False
Processes on Unices Stop-and-think The only way to get rid of zombies/defunct processes is to reboot the system. True False
Processes Running processes Background, foreground and priorities
Running processes Processes in the shell I want my prompt back! n Background processes n Start with & n Ctrl-Z + bg n Move to foreground n fg n Ctrl-C kill the process n List running tasks n jobs n Detach from the shell n disown
Running processes Processes in the shell supinfo@localhost:~$ yes > /dev/null ^Z [1]+ Stopped yes > /dev/null supinfo@localhost:~$ bg [1]+ yes > /dev/null & supinfo@localhost:~$ cat /dev/zero > /dev/null & [2] 1861 supinfo@localhost:~$ jobs [1]- Running yes > /dev/null & [2]+ Running cat /dev/zero > /dev/null & supinfo@localhost:~$ fg cat /dev/zero > /dev/null ^Z [2]+ Stopped cat /dev/zero > /dev/null supinfo@localhost:~$ bg [2]+ cat /dev/zero > /dev/null & supinfo@localhost:~$ fg %1 yes > /dev/null
Running processes Priority So the last will be first, and the first last n Priority (PR) n Kernel-computed n Niceness n Many elements n -20 > 19 n Default 0 n Niceness n Only root can go negative
Running processes Niceness Starting a niced process n nice command n Defaults to 10 n Can be set [user@linux ~]$ nice [option] cmdline -n value: Run the process with the specified nice value
Running processes Niceness Modifying the nice value of a running process n renice command n PID s n Users n Only root can renice other s processes [user@linux ~]$ renice [ n] priority options -p pid: Renice the PID process -u user: Renice processes owned by user
Running processes Stop-and-think Do you have any questions?
Running processes Stop-and-think Only root can run processes with a negative nice value. True False
Running processes Stop-and-think Only root can run processes with a negative nice value. True False
Running processes Stop-and-think Users can always renice their own processes. True False
Running processes Stop-and-think Users can always renice their own processes. True False
Processes Listing processes Unix task managers
Listing processes Show processes List running processes [root@linux ~]# ps [options] Options none -u user -e -ef aux Definitions Processes running in the current user/shell Processes owned by user All processes (System V syntax) All processes, long form All processes (BSD Syntax)
Listing processes Show processes Filter processes [root@linux ~]# pgrep [options] pattern Options Definitions -l -U user, -G group, î -v Show process name Processes owned by user (list is or ed) Processes owned by group (list is or ed) Inverted match: Show process that do not match
Listing processes Interactive tools TUI-based process management. n Interactive tools n Keyboard controlled n Monitor system activity n top n Well-known n De facto standard n Old n Limited (list size, ) n htop n Fixes top limitations
Listing processes Stop-and-think Do you have any questions?
Listing processes Stop-and-think The ps aux and ps aux commands are both valid and have the same meaning. True False
Listing processes Stop-and-think The ps aux and ps aux commands are both valid and have the same meaning. True False
Processes Signals Primitive IPC
Signals Signal definition What s a signal? n Primitive IPC/Soft IRQ n Signal other process n Signal self n Events n Modem Hang up n Timer elapsed n Errors n Broken Pipe n Segmentation Fault n Custom meanining
Signals Common Signals Complete list with kill -l number Description 15 SIGTERM 9 SIGKILL 11 SIGSEGV 1 SIGHUP
Signals Sending signals From command line [user@linux ~]$ kill [options] [pid %job_id] Options Definitions -l -num -signal List signals Send signal n num. Defaults to SIGTERM(15) Send signal named signal. (SIGKILL or KILL)
Signals Sending signals From command line [user@linux ~]$ killall [options] [name] Options Definitions -l -s signal -u user List signals Send signal (name or n ). Defaults to SIGTERM(15) Select only processes owned by user
Signals Sending signals From command line [user@linux ~]$ pkill [options] pattern options: Same as pgrep -signal: Send signal (name or n ). Defaults to SIGTERM
Signals Part 4 Stop-and-think Do you have any questions?
Signals Stop-and-think To kill a job with the kill command, you must get its PID before. True False
Signals Stop-and-think To kill a job with the kill command, you must get its PID before. True False
Processes Course summary Priority/ niceness What s a process Signals Zombies Jobs
Processes For more If you want to go into these subjects more deeply, Publications Courses Linux Technologies: Edge Computing Linux system administration Web sites www.supinfo.com www.labo-linux.com www.blackbeltfactory.com Conferences FOSDEM RMLL Solutions Linux
Congratulations You have successfully completed the SUPINFO course module n 09 Processes
Processes The end n Kill with caution n Disown before closing your terminal