UNIX Session CRUX Day 2
Process Related information:
PCB ( Process control block ) will hold the information about the process, like
When you kill any process then the O.S will send SIGKIL signal to the kernel.
Components of the PCB:
PID , UID,GID,Signals,Umask, environmental variables, Time, File discriptions (0
stdout, 1 stdin,2 Stderr )
When you fork the process the child process will inherit the properties of the parent
process.
Ps –u username (to select the processes belonging to specific user)
Kill -9 sends the uninterrputable kill signal. (SIGKILL)
GREP , Find & Extraction of Data:
Grep ,egrep,fgrep (uses meta charectors).
Regular expressions:
. matches any single character.
* matches any number of characters
+ matches 1 or more of previous character.
{ } specifies number of occurrences of the characters
-c prints counts of matching lines only
-i ignore case
-s suppresses file error messages
-v prints non-matching lines
Fgrep:
Fgrep –f [Link] /usr/dict/words
Search for all the words in [Link] in filt /usr/words
Fgrep does not use regular expression.
Find :
-atime days accessed in #days
-ctime days changed in #days
-mtime days modified in #days
-type flag file of specific type
-user name owned by specific owner
Ex: find /usr -atime -10 ( accessed in 10days)
Find /usr -atime +10 (not accessed in 10days).
Actions on the find
-exec
-ok (confirmation of the executed command on find)
-print
Ex : find – name “core” exec rm –f { } \ ;
( this will find the core files and removes them).
Cut and paste commands:
Cut -c 10-20 xxx
Cuts characters from 10 -20 in xxx.
Cut –f5 –d: /etc/ passwd
From field5 of the passwd file ,use :delimiter( here in this case the delimiter is “ : “
Paste :
Split:
Splits a file into smaller files
Redirection commands :
Tee
>output replaces or creates
>> appends or creates
< input from file
<< upto selected text
>& both stdout & stderr
Inorder to store the error messages in a file
Ex: cat filen 2>ranga
( 2 is used here for the error messages).
VI EDITOR COMMANDS
Vi editor should have the term as VT100.
Else
Setenv TERM vt100.
Modes of VI editor:
i - insert text to ledt of cursor
I - insert text at the beginging of the line
o- open new line below the cursor
O- open new line above
rch - replace single char under cursor with ch
R replaces text from cursor to right
S – replaces entire line
s- replaces single character.
Wq - Saves the file and quits
x: same as above
0 – beg of the current line
^ first char of cur line
$ end of line
Dw delete word
Nx ndw ndd ( deletion of the lines and characters where n – is 10 or 20 etc)
D$ delete end of line.
u Undoes the effect of the previous command
U undoes all changes on current line
. Repeats previous command
: set all ( will show all the settings for the vi editor)
(to change the settings use :set ).
Showmode/noshowmode - mode indications
Use Hidden file - .exrc ( to set the command options) for the users.
A shell can also be started from vi editor
Ex : while working on shell you just give
: !sh
Unix Administation
Startup and shutdown:
On startup O.S the processes that will be started are :
Post ( power on self test)
Boot Process ( Root file’s Bottblock ‘s data
Boot Program
Init Phase: (intial processes will be started).
Checks the new hardware
Loads kernel into memory
Init phase will start default in multiuser mode
(single user mode is used for administrator )
Dmesg (command) can be used to view bootmessages.
Initialization scripts will be present in /etc/rc2 , /etc/rc2.d
(you can create your own initialization scripts and should be placed in rc3.d as a softlink
exceeding the runlevel 99)
Creating initialization script :
Make sure that the script should present in /etc/init.d and linked to /etc/rc3 directory.
INIT runlevels :
0 – shutdown
Q or q – force the system to reread the inittabfile
1- single user ode, S or s on some systems,only console is active
2- multiuser mode,traditional state,more than one user
3- network mode,like 2( we are now in this level)
4-user defined
5- hardware/firmware state.
6- shutdown and automatic reboot
Who –r = wil display current runlevel
To know the process monitoring the resource usage and all Needs to use “prstat” .
Prstat –a swap , prstat –a cpu
( whenever the process doesn’t find enough space on RAM then it will get the swap area
and starts using this area treating it as Virtual RAM).
(Swap area should be normally twice the size of RAM).
Sync : command used for writing the dirty data two disk.