Lab 3 APPLIED INFORMATICS Processes. Bash characteristics. Command type. Aliases.
Today... /proc /run 1. PROCESSES 2. BASH CHARACTERISTICS 3. COMMAND TYPES 4. ALIASES $$ $PPID pidof ps pgrep kill killall pkill ps -C ps ax /proc/cpuinfo sleep top /run 2
FILE SYSTEM HIERARCHY 3
FILE SYSTEM HIERARCHY 4
/proc a means of interaction with the kernel cata@debian:~$ ls /proc 5
/proc files in /proc are continuously updated cata@debian:~$ date cata@debian:~$ ls al /proc after a while: cata@debian:~$ ls al /proc 6
/proc size 0 is displayed for lots of non-empty files in /proc cata@debian:~$ ls al /proc/cpuinfo cata@debian:~$ file /proc/cpuinfo cata@debian:~$ cat /proc/cpuinfo 7
/proc most files in /proc are read-only some ask for root permission some can be overwritten lots of files in /proc/sys can be overwritten 8
PROCESSES 9
Terms process: compiled source code running in the system PID: process ID (identifier) Each process has an ID. PPID: parent process ID Each process has a parent process. 10
init PID = 1 does not have a parent is started by the kernel is adoptive parent for all orphan processes 11
kill when the execution of a process is ended, it dies a process can be killed with the command kill 12
daemon processes being launched at start up run in background daemons never die 13
zombie when a process is killed and still appears as running in the system, then that process becomes a zombie. a zombie cannot be killed because it is already dead. 14
COMMANDS FOR PROCESSES 15
$$ & $PPID echo $$ returns the ID of the process associated to the bash cata@debian:~$ echo $$ echo $PPID returns the ID of the parent process of the process associated to the bash cata@debian:~$ echo $PPID cata@debian:~$ echo $$ $PPID 16
pidof pidof process_name returns the ID of the process specified by its name cata@debian:~$ pidof iceweasel cata@debian:~$ pidof init 17
The relationship parent/child cata@debian:~$ echo $$ $PPID cata@debian:~$ bash cata@debian:~$ echo $$ $PPID cata@debian:~$ bash cata@debian:~$ echo $$ $PPID cata@debian:~$ ps cata@debian:~$ exit cata@debian:~$ ps cata@debian:~$ exit 18
ps cata@debian:~$ ps displays the processes associated to the bash cata@debian:~$ ps ax displays all the processes in the system cata@debian:~$ ps C process_name displays details of a specified process 19
pstree displays the processes in the system under the form of a tree cata@debian:~$ pstree 20
pgrep pgrep process_name returns the process ID for all the processes containing the specified name cata@debian:~$ pgrep gnome 21
grep cata@debian:~$ ps ax grep gnome returns all the processes in the system containing gnome in their name 22
top returns all the processes in the system under the form of a list cata@debian:~$ top Press h (help) for help. You can sort the list according to various criteriae. 23
Starting a process processes can be started from the terminal: cata@debian:~$ iceweasel Troubles? cata@debian:~$ iceweasel & starts the process in the background (so the bash becomes active) 24
Starting a process cata@debian:~$ sleep 10s cata@debian:~$ sleep 10s & cata@debian:~$ ps ax cata@debian:~$ ps -C sleep cata@debian:~$ sleep 1000 &... 25
kill kill process_id comand used for stopping a process cata@debian:~$ kill 3380 26
Signals for kill kill l (the letter l, not the digit 1!) cata@debian:~$ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX 27
kill -1 (SIGHUP) kill -1 process_id signal used to force a process to re-read its configuration file 1) SIGHUP cata@debian:~$ kill -1 1 Similarly: kill -HUP process_name 28
kill -15 (SIGTERM) kill -15 process_id command used to stop a process 15) SIGTERM cata@debian:~$ kill -15 3880 cata@debian:~$ kill 3880 29
kill -19 (SIGSTOP) kill -19 process_id suspends a process 19) SIGSTOP cata@debian:~$ kill -19 3880 30
kill -18 (SIGCONT) kill -18 process_id resumes a suspended process 18) SIGCONT cata@debian:~$ kill -18 3880 31
pkill/killall pkill process_name kills a process by its name (not process_id) cata@debian:~$ pkill iceweasel cata@debian:~$ kill 2242 cata@debian:~$ killall iceweasel 32
top You can also kill processes from the top list. cata@debian:~$ top Press k key to kill a process. Type in the process ID. Confirm the deletion. 33
BASH CHARACTERISTICS 34
Remember... echo displays the input received from the keyboard basic command in this lab: important command! Try: cata@debian:~$echo It is snowing outside! 35
Remember... Bash: Bourne Again Shell cata@debian:~$ command interface used in the most Linux systems command interpreter in this lab: bash characteristics 36
Bash characteristics a command we type in the terminal is processed (and modified) by the bash, then executed first step: the bash scans the command then: divides the commands in arguments to be modified 37
Arguments each piece of text separated by one or several spaces or by tab, is considered an argument the command is an argument too Argument 3 Argument 5 cata@debian:~$echo It is Argument 1 Argument 2 Argument 4 (the command) Separator 2 Separator 1 (1 tab) (1 space) snowing outside! Separator 3 (2x space) 38
Arguments echo returns the arguments separated by a single space, no matter what the separator is Try: cata@debian:~$echo It is snowing outside! cata@debian:~$echo It is snowing outside! cata@debian:~$echo It is snowing outside! cata@debian:~$ echo It is snowing outside! 39
echo & by using you can avoid deletion of extra spaces and tabs Try: cata@debian:~$echo It is(tab)snowing outside! cata@debian:~$echo (2xspace)It is snowing outside! 40
echo & by using you can avoid deletion of extra spaces and tabs Try: cata@debian:~$echo It is(tab)snowing outside! cata@debian:~$echo (2xspace)It is snowing outside! 41
echo e & / with e option, or, /n and /t you can insert new lines or tabs in the text you want to display Try: cata@debian:~$echo -e A line with \na newline cata@debian:~$echo -e A line with \na newline cata@debian:~$echo -e A line with \ta tab cata@debian:~$echo -e A line with \ta tab 42
COMMAND TYPE 43
Command type 1) External commands having their own binary file saved locally on the computer (most can be found in bin and in sbin) 2) Internal (builtin) commands are integrated in the shell 44
type returns the command type Try: cata@debian:~$type cd cata@debian:~$type cat 45
type some commands are both internal and external internal type has priority in order to execute an external command the path to the binary file must be specified cata@debian:~$type a echo cata@debian:~$/bin/echo 46
which displays the path to the binary folder corresponding to an external command cata@debian:~$which cp ls cd mkdir pwd 47
ALIASES 48
alias the shell enables the creation of aliases for commands aliases are created with the purpose of replacing a difficult to recall command name with an easy name Create the file count.txt in which you write: 1, 2, 3 on three different lines. Then, try: cata@debian:~$alias reversed=tac cata@debian:~$reversed count.txt 49
alias aliases can be created in order to substitute complex commands cata@debian:~$alias md= mkdir p ~/D1/D2/ D3/D4 50
alias in order to list all the existing aliases in the computer : cata@debian:~$alias Try: cata@debian:~$alias invers md cata@debian:~$which md 51
unalias in order to deallocate an alias: cata@debian:~$unalias reversed 52
That s all for today www.ace.catalinamancas.ro catalina.mancas@dcti.ucv.ro