Sunday, November 10, 2019

fork() - Theory


fork() is used create a new child process.
Ø  No arguments
Ø  Process ID of the child process
Ø  After the execution of fork() command both parent & child processes are starting their execution from the next line.

Conditions of  fork()
Ø  fork() > 0 -: not only a child process but also a parent process (Successfully child process created.)
Ø  fork() == 0 -: a child process (Successfully child process created.)
Ø  fork() < 0 -: error in memory allocation (Unsuccessful child process)

Example:



Access permission


1.       chmod
Type
Access permission
User
Group
Other
Directory
d
rwx
r-x
r--
File
-
r-x
r-x
r--
command
u+(access per.)
g+(access per.)
o+(access per.)


Description
Letter representation
Numerical value
readable
r
4
writable
w
2
executable
x
1

Ø  chmod numericalValue filename.fileFormat >>>Ex: chmod 777 file1.txt
Ø  chmod command+letterRepresentation filename.fileFormat >>>Ex: chmod g+w file1.txt

2.       chwon
Ø  chown -R userName:groupName directoryName -: to set a user from the related group as the owner of related directory
>>>Ex: chown -R daniel:admins dir1


Users and Groups



Ø  groupadd groupName -: to create a group
Ø  useradd -G groupName userName -: to add a user to the related group
Ø  passwd userName  -: set a password to the related user
Ø  usermod -a -G  groupName userName -: to add a existing user to a existing group
Ø  login
press “Enter”
give username and password -: to login as related user
Ø  logout -: logout from the user
Ø  grep groupName /etc/group -: to search a group
Ø  userdel userName  -: to remove a user
Ø  groupdel groupName -: to remove a group


File & directory manipulation

1.  cp – copy files and directories
Ø  cp  file1.fileFormat file2.fileFormat -: to copy file1 contents to file2 in same path
Ø  cp  file1.fileFormat /path/file2.fileFormat -: to copy file1 contents to file2 in different path
Ø  cp  file.fileFormat directoryName -: to copy file into a directory in same path
Ø  cp  file.fileFormat /path/directoryName -: to copy file into a directory in different path
Ø  cp -r  directory1Name directory2Name -: to copy directory1 contents to directory2 in same path
Ø  cp -r  directory1Name /path/directory2Name -: to copy directory1 contents to directory2 in different path

2. mv – move files and directories
Ø  mv  file1.fileFormat file2.fileFormat -: to move file1 contents to file2 in same path
Ø  mv  file1.fileFormat /path/file2.fileFormat -: to move file1 contents to file2 in different path
Ø  mv  file.fileFormat directoryName -: to move file into a directory in same path
Ø  mv  file.fileFormat /path/directoryName -: to move file into a directory in different path
Ø  mv  directory1Name directory2Name -: to move directory1 contents to directory2 in same path
Ø  mv  directory1Name /path/directory2Name -: to move directory1 contents to directory2 in different path

3. rm – remove files and directories
Ø  rm filename.fileFormat -: to remove the file
Ø  rm -r directoryName -: to remove the directory

4. find – find files and directories
Ø  find /path -name filename.fileFormat -: to find the file concerning case-sensitive
Ø  find /path -iname filename.fileFormat -: to find the file concerning case-insensitive
Ø  find . -type d -name directoryname  -: to find the directory
Ø  find . -type f -name filename.fileFormat -: to find the file
Ø  find . -type f -name “ *.fileFormat-: to find all files in related file format

Saturday, November 9, 2019

Text editors


1.       nano
Ø  nano -: to start nano text editor
Ø  ctrl+x -: to exit from nano text editor. Then press “y” & give a name with file format to save the file.

2.       touch
Ø  touch filename.fileFormat -: to create a new text file

3.       more
Ø  more filename.fileFormat -: to view the text file

4.       cat
Ø  cat filename.fileFormat -: to view the text file
Ø  cat -n filename.fileFormat -: to display the content with the line number
Ø  cat *.fileFormat -: to view the all text files’ contents.
Ø  cat >filename.fileFormat
                  press enter
                  type file content
                  press enter
                  ctrl+d -: to create a text file
Ø  cat file1name.fileFormat file2name.fileFormat >filename3.fileFormat  -: concatenate existing 2 files and create new file
Ø  cat filename2.fileFormat >filename1.fileFormat  -: to copy the content of file2 to file1
Ø  cat filename1.fileFormat >>filename2.fileFormat  -: to append the contents from file1 to file2

5.       vi – commands are case sensitive
I.            Command mode
Ø  vi fileName.fileFormat  -: to create a text file.
II.            To switch between 2 modes press “i”.
III.            Insert mode
Ø  Enter the content


Editing Commands
i
Insert at cursor
a
Write after cursor
A
Write at the end of line
ESC
Terminate insert mode
u
Undo last change
U
Undo al changes to the entire line
o
Open a new line
dd
3dd
Delete line
Delete 3 lines
D
Delete contents of line after the cursor
C
Delete contents of a line after the cursor and insert new text. Press “Esc” to end insertion.
dw
4dw
Delete word
Delete 4 words
cw
Change a word
x
Delete character at the cursor
r
Replace character
R
Overwrite characters from cursor onward
s
Substitute one character under cursor continue to insert
S
Substitute entire line and begin to insert at the beginning of the line
~
Change case of individual character
Commands for moving within a file
k
Move cursor up
j
Move cursor down
h
Move cursor left
I
Move cursor right
Commands for saving and closing the file
Shift+zz
Save the file and quit
:w
Save the file while opened
:q
Quit without saving
:wq
Save the file and quit

fork() - Theory

fork() is used create a new child process. Ø   No arguments Ø   Process ID of the child process Ø   After the execution of fork() command ...