Tutorial 1: The Objective of This Tutorial Is To Learn Some of The Basic Concepts in OS With The Help of Linux Commands
Tutorial 1: The Objective of This Tutorial Is To Learn Some of The Basic Concepts in OS With The Help of Linux Commands
The objective of this tutorial is to learn some of the basic concepts in OS with the help of
Linux commands.
1. Run the command ps with various options and explain the output(the important
fields)
$ ps
$ ps e
Use pipe to send output to more to view output one screen at a time. What are Unix
pipes?
$ ps ef
$ pstree to see process tree. Look at the tree and find the bash process. Go up the
tree by using grep to look at parents recursively. Show that init (pid 1) is the root of
this tree as seen by pstree.
$ ps ef | grep [parent]..
2. Run a program and use kill pid to terminate it. E.g. open vi in the background ( tell
them about background processes), and terminate it by its pid.
$ vi abc &
[1] 12175 pid
$ kill 12175
3. df (disk usage) and du(file space usage) commands to view disk status and file space.
4. Create hard link to a file. What is a hard link? Need for hard links?
Assume a file 1.c is present with some text content; run the following commands
$ ln 1.c 2.c
$ ls l
you will see two files with same size and inode number (explain inode here)
Now, delete 2.c, and again run ls li
Repeat the above process but now delete the original file instead of the new one.
Nothing changes except the file name. Why are hard link needed? Directories have at
least 2 links. Why?
5. Create symbolic link to a file. What is a symbolic link aka soft link aka sym link?
$ ln s 1.c 2.c
$ ls li
The output is different this time, 2.c is shown as a symbolic link to 1.c (look at the
first letter in the permission field, and also look at the end of the output line
corresponding to 2.c). The inode is also different. Attempting to read content of 2.c
will result in content of 1.c being read instead. The symbolic link file just contains the
name of the file it is pointing to; you can see this by running:
$ readlink 2.c
it will show 1.c as its content
Copying the symbolic link to another file copies the content of the original file the
symbolic link is pointing to.
$ cp 2.c 3.c
$ ls li to see the inodes
Now delete the symbolic link.
$ rm 2.c
$ ls li
Delete all *.c files.
Repeat the above process of creating symbolic link, but now delete the original file
instead of the symbolic link.
$ ln s 1.c 2.c
$ ls li
$ rm 1.c
The symbolic link remains but the file it points to has become invalid. Try copying
myfile2 to another file.will result in an error.
$ cp 2.c 3.c
cp: cannot stat 2.c: No such file or directory
Why are symbolic links needed?
6. What is sudo? Use sudo for running privileged commands e.g .
$ sudo apt-get install vim
[You may need to enter password]
It will download and install vim from the repository on the Internet.
To uninstall, run
$ sudo apt-get remove vim