Unix System Programming - IA1 Question Bank
Answers
Module 1 Answers (Q1–Q27)
Q1. Construct with a neat diagram to explain Unix architecture.
• Unix architecture has three main components: Kernel, Shell, Applications.
• Kernel: Core of OS, manages memory, CPU, devices, processes (p.4–5, Module 1).
• Shell: Command interpreter, converts user input into system calls.
• Applications: Utilities, editors, compilers, etc. (p.9, Module 1).
• Files & Processes are fundamental entities.
• [Refer diagram: p.9, Module 1]
Q2. List and explain the salient features of Unix Operating
System.
• Multi-user system – multiple users at once (p.5, Module 1).
• Multi-tasking system – concurrent tasks (p.5, Module 1).
• Building block approach – simple utilities combined (p.5–6, Module 1).
• Unix toolkit – filters, compilers, admin tools (p.6).
• Pattern matching – wildcards (*, ?) (p.6).
• Programming facility – shell scripting features.
• Documentation via man pages (p.6).
Q3. Construct with a neat diagram to describe the parent-child
relationship in Unix file system.
• Files arranged hierarchically (tree structure).
• Root (‘/’) is parent of all directories.
• Each directory may contain subdirectories (children).
• Parent-child process relationship: processes are created using fork(), forming a process tree (p.4,
Module 1).
• Diagram: hierarchical file tree (p.20–21, Module 1).
Q4. Identify the differences between internal and external
commands.
• Internal: Built into the shell (e.g., echo, cd, pwd). Do not exist as separate files (p.17, Module 1).
• External: Stored in /bin or /usr/bin (e.g., ls, cat). Have independent existence.
• If both exist, shell prefers internal command.
Q5. Enter the following commands and note your observation
(who, ps, echo $$).
• who → Shows list of logged-in users (p.14–15, Module 1).
• ps → Shows currently running processes.
• echo $$ → Displays process ID of current shell.
Q6. Command to count the number of files in the directory.
• Command: ls | wc -l (p.14, Module 1).
Q7. Evaluate the following expression 12+5, 12*12, 2^8, 9/3.
• Use expr or bc:
expr 12 + 5
expr 12 \* 12
expr 2 \^ 8
expr 9 / 3
(p.12–13, Module 1).
Q8. Display all the users who are logged in to the system with
header.
• Command: who -H (p.15, Module 1).
Q9. Display date of June 17th 2003.
• Command: date -d '2003-06-17' (p.13, Module 1).
Q10. Evaluate expressions and redirect output to a file.
• Command: expr 12 + 5 > [Link] (p.14, Module 1).
Q11. Create a file and display contents.
• Command: cat > file1
(Enter contents)
cat file1 (p.14, Module 1).
Q12. How to increase the link count of a file.
• Command: ln file1 file2 (creates hard link) (p.20–21, Module 1).
Q13. How to find out the type of the file.
• Command: file filename (p.20, Module 1).
Q14. Determine the current working directory.
• Command: pwd (p.17, Module 1).
Q15. Find out the users who are currently logged in.
• Command: who (p.14–15, Module 1).
Q16. Display calendar for given months/dates.
• Command: cal 1 2000 ; cal 2 1999 ; cal 9 7 ; cal ; date '+%d %a %b %Y' (p.16, Module 1).
Q17. Display the Current Date and Time.
• Command: date (p.13, Module 1).
Q18. Display the name of your home directory.
• Command: echo $HOME (p.11, Module 1).
Q19. Create directory SAMPLE and subdirectory TRIAL.
• mkdir ~/SAMPLE
mkdir ~/SAMPLE/TRIAL
cd ~/SAMPLE
cd ~
cd SAMPLE/TRIAL
rmdir ~/SAMPLE/TRIAL (p.14, Module 1).
Q20. Create a directory TEST using absolute pathname.
• mkdir /home/user/TEST (p.14, Module 1).
Q21. Using a single command change from current directory to
home directory.
• cd ~ (p.14, Module 1).
Q22. Remove a directory using absolute pathname.
• rmdir /home/user/dir1 (p.14, Module 1).
Q23. Create files myfile and yourfile, display them.
• touch myfile yourfile
ls myfile yourfile (p.14, Module 1).
Q24. Append more lines in files myfile and yourfile.
• echo 'new line' >> myfile (p.14, Module 1).
Q25. Copy myfile file to emp.
• cp myfile emp (p.14, Module 1).
Q26. Write command to create alias name for a file.
• alias myls='ls -l' (p.18, Module 1).
Q27. Display the inode numbers.
• ls -i (p.14, Module 1).
Module 2 Answers (Q28–Q53)
Q28. Copy content of one file to another file.
• Command: cp file1 file2 (p.9, Module 2).
Q29. Display the inode number of a file.
• Command: ls -i filename (p.2, Module 2).
Q30. Extract the permission of a file.
• Command: ls -l filename (p.2–3, Module 2).
Q31. Extract the link count of a file.
• Command: ls -l filename (second column shows link count) (p.2, Module 2).
Q32. Change the permission of others to read and execute.
• Command: chmod o+rx filename (p.3–4, Module 2).
Q33. Change the permission of group to read and write.
• Command: chmod g+rw filename (p.3–4, Module 2).
Q34. Change the permission to add all the users with execute
permission.
• Command: chmod a+x filename (p.3–4, Module 2).
Q35. Display the output of ls on the screen and redirect it to a file.
• Command: ls | tee [Link] (p.9, Module 2).
Q36. Rename a file with name file1 to exam1.
• Command: mv file1 exam1 (p.9, Module 2).
Q37. Count number of lines in a file.
• Command: wc -l filename (p.14, Module 1; p.9, Module 2).
Q38. Count number of words in a file.
• Command: wc -w filename (p.14, Module 1).
Q39. Display the content of an exe file.
• Command: cat filename (may show unreadable data) (p.20, Module 1).
Q40. Find out whether two files are identical.
• Command: cmp file1 file2 (p.9, Module 2).
Q41. Find names in one file but not in another.
• Command: comm -23 file1 file2 (p.9, Module 2).
Q42. Find common names in two files.
• Command: comm -12 file1 file2 (p.9, Module 2).
Q43. Create a file with permission rw-r-xr--, later change to
rwxrwxrwx.
• Command: touch f1; chmod 754 f1; chmod 777 f1 (p.3–4, Module 2).
Q44. Create a file with permission rw-r-xr--, later change to r--r-----
• Command: touch f2; chmod 754 f2; chmod 440 f2 (p.3–4, Module 2).
Q45. Create a file with permission rw-r-xr--, later change to ---r--r--
• Command: touch f3; chmod 754 f3; chmod 044 f3 (p.3–4, Module 2).
Q46. Create a file with permission rw-r-xr--, later change to --------
• Command: touch f4; chmod 754 f4; chmod 000 f4 (p.3–4, Module 2).
Q47. Display process attributes.
• Command: ps -l (displays PID, PPID, UID, priority, etc.) (p.9, Module 2).
Q48. List and explain the significance of 7 columns of ls -l
command.
• Columns:
1) File type & permissions
2) Links
3) Owner
4) Group
5) Size
6) Modification time
7) Filename (p.2, Module 2).
Q49. List and explain the different ways of setting the file
permissions.
• Relative permissions: chmod u+x f1, g-w f1, etc.
• Absolute permissions: chmod 755 f1 (octal notation) (p.3–4, Module 2).
Q50. List and explain the three categories of files.
• Ordinary/Regular (Text & Binary)
• Directory files
• Device files (p.20–21, Module 1).
Q51. List and explain the recursive behavior of a command with
examples.
• Recursive option (-R) applies operation to all subdirectories/files.
• Example: chmod -R a+x dir1; ls -R (p.5, Module 2).
Q52. Explain the steps involved in shell interpretive cycle.
• Steps:
1) Shell issues prompt.
2) Reads command.
3) Expands metacharacters.
4) Passes to kernel.
5) Waits for execution.
6) Displays prompt again (p.6, Module 2).
Q53. Explain the standard files and redirection.
• Standard Input (0: keyboard), Standard Output (1: screen), Standard Error (2: screen).
• Redirection operators: <, >, >>, 2> etc. (p.8–9, Module 2).