INFX 450 Exam 2
vi
default editor in all linux systems
ps (process status)
displays a snapshot of processes currently running. non-interactive
Jobs command
displays active jobs and identifies if foreground, background, or stopped. allows the user to directly interact with processes in the current shell.
ps -e
displays every active process( all users logged in)
summary of disk usage
du -s
top
dynamically displays running processes; interactive display process statistics continuously until stopped.
\
escape sequence that tells the interpreter not to interpret the following character, but rather use it as a literal. Ex. if you want to search for a "." use "\." so egrep \. filename
list of empty files
find ~ -empty
SIGHUP (kill signal 1)
hang-up; terminates communication if a signal is lost; restarts the process with the exact same PID
if then else statement
if something is true -> do it, or if the next something is true -> do it, ... if now of the above are true, do else
if then statement
if something is true do it, otherwise execute the then portion
{}
indicates number of times to match the preceding character
ppid
parent process ID
foreground process
A process for which the BASH shell that executed it must wait for its termination.
background process
A process that runs "behind the scenes" with a low priority, does not require input, and rarely creates output. (11)
Child Process
A process that was started by another process (parent process).
Fork() system call
Creates a new process
VariableName=Value
Creating and assigning a value to a variable
slide 12 Ch. 7 Part 2
Different echo options for input and output
-20
Highest priority level
& <- added to the end of the command
How to launch a background process?
nice -n 12 my-job
Launch my-job setting the nice value to 12
-20 to +19
Niceness value is an integer that ranges from
niceness value high nice value = lower priority
Priority is established by setting the
foreground or background
Process can run in either?
date
Shows the date in bash
Systemd
The first process that spawns at the system boot; is the parent of all processes. First to start and runs until system shuts.
Parent Process
The original process that initiates and controls execution of a child process.
fg job_ID, fg is for stopped jobs
To move a background process to the foreground.
bg
To move a foreground process to the background
bg #
To resume the process in the background.
fg #
To resume the process in the foreground.
Ctrl-Z
To suspend a process in the foreground
$! /bin/bash date du -s ~ find ~ -empty
Write a script to run a simple status report: show the date, summary of disk usage, and a list of empty files
Process
a running program; any program that is executing on your system
regular expression (regex)
a special text string for describing a search pattern. used for searching, text processing, and data validation. used to identify and manipulate specific pieces of data.
variable
a symbolic name for a memory location that we can assign values, read the data, and manipulate its contents.
-Power- options can usually be implemented through the GUI, but it takes more resources, time, and operactions -sometimes you dont have access to the GUI, if youre remotely logged in, GUI has failed, have a need for a minimal installation
advantages of using a text line editor:
vi mode (command mode)
all keys pressed by the user are interpreted as commands press ESC to enter command mode
loops
allow you to execute commands repetitively
text editors
allows you to edit text files from GUI text editor or a command line text editor.
interpreter
bash is an
shutdown commands
brings the system down in a secure way. when used all logged in users and processer are notified that the system is going down, and no further logins are allowed.
SIGKILL (kill signal 9)
brute-force kill; if th e process was hung badly, this option will force it to stop; Linus immediately kills with no chance for process to clean up
command
command name
pcpu
cpu utilization
?
preceding character can appear 0 or 1 times exactly
*
preceding character can appear 0 or more times
+
preceding character can appear 1 or more times
pid
process ID
User processes
process created by the user when he/she enters a command at the prompt
stat
process status
if condiftion
returns two values and returns true or false
ps -aux
same as ps -e just displays a different format. a: all processes running u: user oriented format x: list all processes not attached to a terminal
#! /bin/bash echo Hello $USER. Here are the running processes. ps
script that greets the user and shows the running process list
#! /bin/bash ls -l | grep '^d'
script that uses "ls" to display only directories
Finding files and directory's through script
slide 22 Ch. 7 part 2
if statement
something is true then do x
metacharacters (regex)
special characters that are applied to a specific literal character and change the rules for matching that literal character Ex. ". * +"
literal characters (regex)
specific characters that must match precisely, in the order given, and with correct case. Ex. "ca" matches car and can
SIGTERM (kill signal 15)
tells process to terminate immediately; default signal sent by kill; allows process to clean up after itself before exiting.
find ~ -empty >> empty.txt
the empty files are written to the text file empty.txt
vi mode (replace mode)
this mode isfor typing text in an over write mode press "R" to enter this mode
"if" statements
to make a decision in your script us
vi filename
to open a new text file on vi with a specific file name
read
to read input from the keyboard; reads data until you press the enter key Ex. read X Y Z user would input 2 4 6 and these numbers would be assigned
Case statement
used for comparisons similar to multi-level if then else statements matches a variable against several values
[]
used to specify a list of choices; ,atch any one single charcter in the list
user
username
ps -al
view all process with the long format
"$"
when you want to view the contents of a variable
read -p "Enter 5 integer values: " one two three.. let result="($one + $two + $three + $four + $five)/5" echo "the average is $result"
write a script that prompts the user to input 5 values and output the average of the 5 values
#! /bin/bash hostname arch who
write a script that provides some basic system information (hostname, CPU info, Who is logged in)
./SysTest.sh >> output.txt
write the output of the entire script to a text file using redirection
To do math in bash
you must denote the values in variable are to be interpreted as numbers and not strings. to do so precede assignment statement with "let" Ex. let a=n+1
i (insert)
mode to enter text
nice
niceness value
To create a script
1. Create script file in a text editor; First line is #! /bin/bash 2. Change permissions with chmod to make the file executable use "chmod 745" 3. Run script using ./filename
shell script
is a series of commands written in a file. used for repetitive tasks, shortcuts for convoluted commands, easy to use command line interface.
TTY
is the controlling terminal associated with the process, run this to see the terminal name
grep (Global Regular Expression Print)
is used to search text. It searches the given file for lines containing a match to the given strings or words.
kill
kill a process by PID
killall
kill a process by name
egrep
lets you search with the extended metacharacters.
+19
lowest priority level
. (metacharacter)
matches any character (except line breaks) Ex. "b.t" matches bit and but, DOES not match boot or b123t
$
matches end of line
^
matches start of line
vi mode (Input mode)
mode is for inserting new text and editing/replacing existing text press "i" to enter mode
