- In Linux, whether working from shell or GUI, all processes are runing in the shell.
Untitled
- A critical kernel function called the scheduler constantly shifts processes on and off the CPU.
- Zombie Process: sometimes, a child process completes, but its parent process has not asked about its state. it is not really alive, but still shows up in the system’s list of processes.
- Unix-like systems, kernel devides CPU (1 core, 1 thread) time into small slice and run each inturn. The PID is used to track process state, CPU usage, memory use, precisely where resources are located in memory, and other characteristics.
Untitled
ps aux | grep [keyword] # ps aux: displays all processes of all usersps aux | head -10ps axo stat,priority,pid,pcpu,comm | head -10ps -u # display information of processes for a specified userps -ef # displays all the processes in the system in full detailps -eLf # displays one line of information for every threadps -fC [command_name]pstreekill -[signal] [pid] # force killkill -SIGKILL [pid]kill -9 [pid] # same as aboveterm [pid] # terminate gracefully
User and Group IDs
- Many users can access a system simultaneously, and each user can run multiple processes. The operating system identifies the user who starts the process by the Real User ID (RUID) assigned to the user.
- The user who determines the access rights for the users is identified by the Effective UID (EUID). The EUID may or may not be the same as the RUID.
- Users can be categorized into various groups. Each group is identified by the Real Group ID (RGID). The access rights of the group are determined by the Effective Group ID (EGID). Each user can be a member of one or more groups.
- Most of the time we ignore these details and just talk about the User ID (UID) and Group ID (GID).
Priorities
- The priority for a process can be set by specifying a
nice value, or niceness. -20 represents the highest priority and +19 represents the lowest. Only root user can renice a process to a negative value to give it higher priority.
- You can also assign a so-called
real-time priority to time-sensitive tasks, a very high priority.
ps lf # show priority# Setting the Priority when Starting Processnice -n [nice_value_increament] /bin/[someSlowProcess]# Changing the Priority of a Runing Processrenice [nice_value_increament] [PID]renice +5 3077 # increase 5sudo renice -5 3077 # decrease 5, must in sudogenome-system-monitor # check priority in monitor
Load Averages
- The
load average is the average of the load number for a given period of time.
- Actively running on a CPU
- Considered runnable, but waiting for a CPU to become available
- Sleeping: i.e. waiting for some kind of resource (typically, I/O) to become available.
- NOTE: Linux differs from other UNIX-like operating systems in that it includes the sleeping processes. Furthermore, it only includes so-called
uninterruptible sleepers, those which cannot be awakened easily.
w# load average (for 1 min, 5 min, 15 min), a single-CPU everagetop# Output:# 1st line: time the system has been up, users logged on, load average as `w`# 2nd line: total processes, the number of running, sleeping, stopped, and zombie# 3rd line: CPU time divided between users (us) and kernel (sy), # and the percentage of user jobs running lower priority (ni), # idle mode (id) should be low if the load average is high, # the percentage of jobs waiting (wa) for I/O, # hardware (hi) vs. software interrupts (si), # steal time (st) is generally used with virtual machines, which has some of its idle CPU time taken for other uses# Prameters of the table # Process Identification Number (PID) # Process owner (USER) # Priority (PR) and nice values (NI) # Virtual (VIRT), physical (RES), and shared memory (SHR) # Status (S) # Percentage of CPU (%CPU) and memory (%MEM) used # Execution time (TIME+) # Command (COMMAND).# You can enter single-letter commands to change its behavior # t: Display or hide summary information (rows 2 and 3) # m: Display or hide memory information (rows 4 and 5) # A: Sort the process list by top resource consumers # r: Renice (change the priority of) a specific processes # k: Kill a specific process # f: Enter the top configuration screen # o: Interactively select a new sort order in the process list # 1: Show every single cpuvmstat -a 2 1000 # all info, every 2 sec, run 1000 timesuptime