Chapter 13: Managing Linux Processes

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Process

A program that has been loaded from a long-term storage device, usually a hard disk drive, into system RAM and is currently being processed by the CPU on the motherboard.

at daemon

A system daemon that runs in the background. the two config files /etc/at.allow /etc/at.deny determine who is able to schedule jobs through at. SYNTAX: at time command CTRL-D when you are done entering commands. atrm (removes jobs) atq (lists pending at jobs)

Process priority level

A value assigned to a process that controls the order in which the program code is executed by the CPU in relation to other code. The higher the number, the lower the priority.

screen (utility)

Allows you to run multiple shell windows from within a single SSH session

Process Heredity

Any process on the system can launch another process. A process which launches a new process is the parent of that process, the new process the child. This defines the heredity of processes.

subshell (forking)

Any time you run a command from within any shell, a second shell session is created, called a subshell, and the process for the command you entered is run within it. The subshell is a separate process in and of itself and has its own PID assigned, its PPID is the shell where the command was entered. This process is called forking.

pgrep (utility)

Essentially, this is ps piped into grep. Output only displays the matching PID by default. -P specifies PPID to match -f specifies process name to match -u specifies username to match -l to view name of process and PID for output

anacron

Similar to cron, it runs commands listed in the /etc/anacrontab file. Difference is that anacron will run "skipped" jobs when it starts up (if the system was off). Fields: 1. Period - recurrence period in days (7=weekly, e.g.) 2. Delay - in minutes, time anacron should wait to execute skipped job after startup 3. Job-Identifier - name used for job's time stamp file 4. Command - command to be run

System Processes / Daemons

System processes (usually) do not provide an application or interface for an end user to use. They typically provide a system service, such as a web server, FTP server, print service, logging service, etc. *most system processes are noted with a "d" at the end, which stands for daemon.*

nohup

Run a command immune to hangups (kill signal 1) SYNTAX: nohup command

killall (command)

Same as kill command but uses the command name of process to be killed. SYNTAX: kill -signal command_name e.g. killall -15 vi

Init scripts

Script used by the init process to start processes on system boot. Most distros use one of two types of init scripts: System V: These init scripts are stored in /etc/rc.d directory, which contains rc0.d through rc6.d directories, each associated w/ a different run level's init script sym links. The sym links point to the /etc/rc.d/init.d directory BSD: Similarly, BSD-style init scripts live in /etc/init.d and contain rc0.d through rc6.d directories w/ sym links that point to /etc/init.d directory.

Foreground vs. Background Processes

When a process is run in the foreground, concurrent action cannot be taken while the process is running w/o opening another shell prompt. However, you can open a process in the background, which will pass back control to the shell prompt while still loading the process normally. *to run a program in the background, append an ampersand character to the command*

Concurrency vs. Multi-Tasking

While it may seem that system is running multiple tasks "concurrently", CPUs can't run multiple processes at the same time. In actuality, they multi-task, switching between processes via a schedule which determines when each process has access to the CPU. The exceptions to this rule are multi-core & hyperthreading.

nice (command)

command used to adjust the niceness value of a process when you START the process. Use "renice" for running processes. SYNTAX: nice -n nice_level command e.g. nice -n -15 vi *you cannot adjust niceness level below 0 unless you are root*

fg (command)

command used to move a background process to the foreground SYNTAX: fg job_ID

bg (command)

command used to move a foreground process to the background SYNTAX: bg job_IDK *before moving a job to the background, you need to stop gain control of the prompt by pressing CTRL-Z. This assigns a background job ID to the process*

Internal Shell Commands

commands that are rolled into the shell program itself. e.g. exit (command) has no executable file. code is stored in the shell program.

User Processes

Processes created by the end user when they execute a command through the shell prompt or GUI. User processes are called from within a shell and are associated w/ that shell session.

Binary Executables

Programs that were originally created as a text file using a programming language such as C or C++. The text file was then run through a compiler to create a binary file that can be processed by the CPU.

systemctl start | stop | restart | status service_name

Syntax to start, stop, restart, or check status of a service on a systemd-style system. Service names reference .service files e.g. systemctl start sshd

Scheduling Utilities (name three)

1. cron daemon 2. anacron daemon 3. at daemon

Commands to view running processes

1. top 2. ps 3. free 4. pgrep

Starting User Processes

to start a user process, enter the command or script name at the command line.

Types of Programs (that start processes)

Binary Executables Internal Shell Commands Shell Scripts

Starting System Processes

Depending on if your system uses init or systemd, you would use either init scripts or service files, respectively.

ps (utility)

Displays a snapshot of current processes running associated with the current shell. Unliked top, ps is not dynamic. Use the -e option to see all processes across the system. -f displays more detail (such as UID and PPID) -l displays it in the long format (i.e. you can see even more detail). -e displays processes for the entire system, not just the current shell. aux - comprehensive command for all users processes, user names, start times, and processes w/o a terminal. RSS is the physical memory in KB used by the process.

top (utility)

Displays running processes on the system, along with several attributes for each process. PID - process ID USER - user who owns process PR - priority level NI - niceness level VIRT - virtual mem. used by process RES - amt. of physical RAM used (kb) SHR - amt. of shared memory used S - status of process %CPU - % of CPU time used by process %MEM - % available physical ram used TIME+ - Total amt. CPU time consumed since start COMMAND - name of command which started process use h for help, and press F to see fields which are available for display. Push U for specific users Push r to re-nice a process push k to kill a process

free (utility)

Displays the amount of free and allocated RAM and swap memory in the system. -m displays memory stats in MBs -t displays totals for each category of info. -s refreshes every specified amount of seconds

Process Status

Possible values include: D - Uninterruptibly Sleeping (will only wake to specific resources) R - Running S - Sleeping (waiting) T - Traced or Stopped - stopped by a signal Z - Zombied (process which exited w/o being released by its parent process)

Process ID Number (PID)

Number assigned to each process that uniquely defines it on the system.

Parent Process ID (PPID) Number

PID of the process that spawned a process. By assigning a PID & PPID to all processes, you can effectively trace the genealogy of all processes on a system.

/etc/init.d/script_name start | stop | restart

Syntax to start, stop, or restart installed services on a BSD-style system. System V would be /etc/rc.d/init.d script_name

Shell Scripts

Text files that are executed through the shell itself.

Systemd & init

The "Grandparent" processes. Depending on which is used, init or systemd is always the first process to start on a system and is assigned a PID of 1 and a PPID of 0. *PID 0 belongs to the kernel*

renice (command)

The command used to alter the nice value of a process currently running on the system. SYNTAX: renice nice_value PID

jobs (command)

The command used to see the list of background processes running in the current shell. Displays a + sign next to the most recently executed job. Jobs can be either: 1. Running 2. Stopped 3. Terminated 4. Done CTRL-Z -- Suspends a job CTRL-C -- Kills a job

crontab command

The command used to view and edit user cron tables. SYNTAX: crontab -e --> create new crontab file crontab -l --> display user's crontab file crontab -r --> remove user's crontab file

kill (command)

Used to kill or terminate a process. SYNTAX: kill -signal PID Main Signal Options: SIGHUP --> Kill signal 1. Restarts the process. SIGINT --> Kill signal 2. Send CTRL-C sequence. Send this one first. SIGKILL --> kill signal 9. Brute force process kill. Last resort. SIGTERM --> kill signal 15. Default kill signal. Tells process to terminate immediately. Send 2nd.

pkill (command)

Used to stop a running process. It is the marriage of grep and kill. You can search for processes that match criteria and send them a kill signal. SYNTAX: pkill -signal -f search_criteria *uses same options as pgrep*

Niceness Value

Value factored into Kernel calculations that determine priority. Values range from -20 to 19. Default value is 0.

cron tab file

crontab files are simple text files containing one job per line. Each line has six fields, separated by tabs. Wildcards are used as a value as well. Field 1 -- Minutes past the hour commands should run Field 2 -- Hour of day when command should run Field 3 -- Day of month command should run Field 4 -- Month of year command should run Field 5 -- Day of week to run. Sunday=0, Sat=6 Field 6 -- The name of command to run *users can create their own crontab files, but they are stored in /var/spool/cron/tabs, not /etc

cron daemon (crond)

system daemon which is used to schedule regularly occurring jobs. It checks the /etc/crontab file each minute for jobs to run. /etc/crontab file references five different directories (hourly, daily, weekly, monthly, cron.d) to categorize scripts which run at different intervals. cron.d is used for anything that doesn't fit the first 4.


Kaugnay na mga set ng pag-aaral

Architecture Semester 1 Exam Review

View Set

#4 Quiz: Confirming Placement of a Nasogastric Tube

View Set

Chapter 20: Achieving Success in the Small Business

View Set

Marketing Management 5504 Quiz 15-28

View Set