29-09-2016, 03:56 PM
1456878856-TELE56002016Assignment4 (1).docx (Size: 328.91 KB / Downloads: 4)
Mandatory requirements:
You must have a COE Account with Courses directory and an FTP client setup on your PC.
Submit your assignments in pdf format (Name: <First-Name>_<Last-Name>_Assignment4.pdf) inside Courses/TELE5600/assignment_turnitin/hw4/directory. (Filename example: Sachin_Sagadevan_Assignment4.pdf)
Assignment must be done on COE machine not COE gateway.
Tip: Press Ctrl+R and type the command to search any command you executed previously.
Theory Questions
1. What is the significance of.bashrc and .bash_profile files in your home directory? [You may use your observations from previous assignment to explain]
Ans. .bash_profile file is read only by login shell when logged in from another host (.profile, or .login, or .zlogin are called depending on which shell we are using). And the config files which are read by interactive shells or pseudo- terminals are .bashrc. .bashrc fie is seen everytime you open a new window and thus the system information we see everytime we login is through the .bash_profile (which we won’t like to see evertime a new window is opened)
2. What are login shell and non-login shell?
Ans. When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.But, if you’ve already logged into your machine and open a new terminal window (xterm) inside Gnome or KDE, then .bashrc is executed before the window command prompt. .bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal.
a) When we open “xterm&” another terminal opens up. Which one is the login shell and which one is the non-login shell?
Ans. The main terminal on which the above command is executed is the login shell (as it has ‘-‘ in front of it) and the one which pops up with /bash/tcsh prompt is the non-login shell. We can also use the command “shopt -q login_shell&& echo 'Login shell' | echo 'No login shell'“ to know which shell we are in (only works in bash as shopt is an inbuilt function)
b) Is there any other way to go to a non-login shell?
Ans. By executing the plain command ‘/bin/tcsh’ on the login shell the non-login shell starts up there itself. To find all the types of shell available on your system, type ‘cat /bin/shells’.
3. What commands can we use to find out following information in Linux:[Illustrate with an example]
a) To find a file type information.Ans. File [file_name] gives the type of the file and its content’s brief info.
b) To find word count and line count of a plain-text file.Ans. Wc –w [file_name] and wc –l [file_name] gives the word and line count in a text file also, ‘nl [file_name]’ gives the line count along with printing the entire file.
c) To check RAM information.Ans. Cat /proc/meminfo | more
d) To search a particular string inside a plain-text file.Ans. Grep “word or sentence” /file_path (if you know)
e) See line numbers after opening a file in vim.Ans. After opening the file type, “ et number” and “set nu!” for not seeing the line number.
f) Jump to a particular line number in vim.Ans. “Vi +line_number file.txt”
g) Read first 10 lines of a file and read last 15 lines of a file.Ans. First 10 lines:- “head -10 filename” and last 15 lines is:- “ last -15 filename”
4. What is a process in Linux? How is ps command related to processes in Linux?
Ans. Process is an executing or running instance of a program. It’s also referred to as tasks. When we execute the ps command the output displayed means this:
PID is a Process ID of the running command (CMD)
TTY is a place where the running command runs
TIME tell about how much time is used by CPU while running the command
CMD is a command that run as current process
a) What are parent and child processes? Ans. In Linux, every process except process 0 (the swapper) is created when another process executes the fork() system call. The process that invoked fork is the parent process and the newly created process is the child process. Every process (except process 0) has one parent process, but can have many child processes. The operating system kernel identifies each process by its process identifier. Process 0 is a special process that is created when the system boots; after forking a child process (process 1), process 0 becomes the swapper process (sometimes also known as the "idle task"). Process 1, known as init, is the ancestor of every other process in the system
b) How to find a parent process of a particular process?Ans. With the command ‘ps –elf’.
c) How to search a process ID of a particular process name.Ans. With ‘ps aux | grep [process name]’ .I gave aux instead of ax coz it gives detailed info. And process I tried was Bluetooth.
5. What does top command do? How to print the following using top:
Ans. TOP stands for table of processes and it produces an ordered list of running processes selected by user-specified criteria, and updates it periodically. Default ordering by CPU usage, and only the top CPU consumers shown (hence the name)
a) Print top output for only a particular process.Ans. top –p [pid]
b) Print the whole top output but only once and exit.Ans. top –n1
6. What are hard links in Linux? Ans. A hardlink is merely an additional name for an existing file on Linux or other Unix-like operating systems
a) What property of a file tells you that it is a hard link to another file? Ans. the same inode number of the file and the number of links (followed by number in front of it which points nowhere) tells that it’s a hardlink to a FILE. If it points to some other location then it means that it is symbolic link.
b) How is a symbolic (soft) link different from hard link? Give at least two differences.
Ans. 1) The symbolic link points to some another file by name for the same inode number. 2) Hard-links only allow same-filesystem linking. Symlinks can point at any path. 3) By extension, if we move the target pointer of a hard-link (which, itself is essentially just a hard-link pointing to an inode), the hard-link still works. Moving the target of a symlink would usually break the symlink. 4) Hard-links (essentially) point to absolute data. Symlinks can point to relative paths (eg ../parent.file)
7. Can you compare some of the following features in Linux with Windows?
a) Importance of File extensions.Ans. UNIX/Linux does not have the same early DOS / CP/M heritage that Windows does. So extensions are generally less significant to most UNIX utilities and tools. In windows the extension is the main classification of any file system.
b) What is the equivalent of a Symbolic link in Windows PC.Ans. the command ‘mklink’ (fired on command prompt pointing to C drive) is the equivalent of symbolic link in windows.
8. What is LXC? Keep your answer brief.Ans. it is an operating system-level virtualization technique for running various independent Linux systems / containers on a single machine. It doesn’t provide a virtual machine for only gives a virtual environment which has its own CPU, memory, block I/O, space, network etc.