Linux Programming, Semester 4(2019-22), Model Examination OCT 2021

 SAINTGITS COLLEGE OF APPLIED SCIENCES

          PATHAMUTTOM, KOTTAYAM


Model Examination, October 2021

Department of Computer Applications, Semester 4

LINUX ADMINISTRATION

Total : 80 marks Time: 3 hours

Section A

Answer any 6 questions. Each question carries 3 marks.

(Write in not less than a paragraph)

  1. What is Linux?

Linux is an open source operating system (OS). An operating system is the software that directly manages a system’s hardware and resources, like CPU, memory, and storage. Linux is a free, open source operating system, released under the GNU General Public License (GPL). Anyone can run, study, modify, and redistribute the source code, or even sell copies of their modified code, as long as they do so under the same license.

  1. What is kernel

        It is the heart of Linux Operating system which is responsible for all major activities. There is only one kernel for each system. The Linux kernel is the main component of a Linux operating system (OS) and is the core interface between a computer’s hardware and its processes. It communicates between the 2, managing resources as efficiently as possible.

The kernel has 4 jobs:

  1. Memory management: Keep track of how much memory is used to store what, and where

  2. Process management: Determine which processes can use the central processing unit (CPU), when, and for how long

  3. Device drivers: Act as mediator/interpreter between the hardware and processes

  4. System calls and security: Receive requests for service from the processes

  1. What is ps command?

     PS command is used to show which processes are running in a system The ps command, short for Process Status, is a command line utility that is used to display or view information related to the processes running in a Linux system. 

  1. What are the variables in shell script?

     A variable is simply a placeholder for some value. The value can change; however, the variable name will always be the same. Shell variables are capitalized by convention. The shell maintains two lists of variables:
1. Those local to the current shell
2. Those global to all shells (environment variables).

  1. What is the use of echo command?

          echo command in linux is used to display line of text/string that are passed as an argument . This is a built in command that is mostly used in shell scripts and batch files to output status text to the screen or a file.

Eg: echo “HAI”

  1. What is shell?

       A shell is a program that provides an interface between a user and an operating system (OS) kernel. An OS starts a shell for each user when the user logs in or opens a terminal or console window.

  1. What is chmod command?

   The Linux command chmod allows you to control exactly who is able to read, edit, or run your files. Chmod is an abbreviation for change mode

  1. Define the term super user.

          The superuser is a special user account used for system administration. Depending on the operating system (OS), the actual name of this account might be root, administrator, admin or supervisor. 

  1. What is rpm?

       The RPM Package Manager (RPM) is a powerful package management system used by Red Hat Linux and its derivatives such as CentOS and Fedora. RPM also refers to the rpm command and . rpm file format. rpmis a low-level command-line tool for installing, querying, verifying, updating, and removing RMP packages.

  1. What are the advantages of Apache server?

  • Apache is open-source, and anyone can get it for free

  • Customizable code can be adjusted to the needs

  • Ability to add more features and modules to improve functions

  • Highly reliable and excellent performance

  • Apache is straightforward to install

  • Immediate recording of changes

  • Can be run on every operating system

  • Actively maintained and upgraded by a community

  • Highly flexible Web Server

  • Impressive Documentation that is quite extensive and helpful


  1. What is DHCP.

      DHCP (short for Dynamic Host Configuration Protocol) is a client/server protocol that enables a server to automatically assign an IP address and other related configuration parameters (such as the subnet mask and default gateway) to a client on a network.

12. Differentiate grep and egrep.

grep and egrep does the same function, but the way they interpret the pattern is the only difference.

Grep stands for "Global Regular Expressions Print", were as Egrep for "Extended Global Regular Expressions Print". The pattern often treated as a regular expression, for which e in egrep stands for "Extended Regular Expressions" abbreviated 'ERE' is enabled in egrep.

 


(6 x 3 = 18 Marks)

Section B

Answer any 4 questions. Each question carries 8 marks.

(Write in not less than 2 pages)

13.Explain Linux architecture.

  Architecture of Linux

The Linux operating system's architecture mainly contains some of the components: the Kernel, System Library, Hardware layer, System, and Shell utility.

1. Kernel:- The kernel is one of the core section of an operating system. It is responsible for each of the major actions of the Linux OS. This operating system contains distinct types of modules and cooperates with underlying hardware directly. The kernel facilitates required abstraction for hiding details of low-level hardware or application programs to the system. There are some of the important kernel types which are mentioned below:

  • Monolithic Kernel

  • Micro kernels

  • Exo kernels

  • Hybrid kernels

2. System Libraries:- These libraries can be specified as some special functions. These are applied for implementing the operating system's functionality and don't need code access rights of the modules of kernel.

3. System Utility Programs:- It is responsible for doing specialized level and individual activities.

4. Hardware layer:- Linux operating system contains a hardware layer that consists of several peripheral devices like CPUHDD, and RAM.

5. Shell:- It is an interface among the kernel and user. It can afford the services of kernel. It can take commands through the user and runs the functions of the kernel. The shell is available in distinct types of OSes. These operating systems are categorized into two different types, which are the graphical shells and command-line shells.

The graphical line shells facilitate the graphical user interface, while the command line shells facilitate the command line interface. Thus, both of these shells implement operations. However, the graphical user interface shells work slower as compared to the command-line interface shells.

There are a few types of these shells which are categorized as follows:

  • Korn shell

  • Bourne shell

  • C shell

14 . Explain different process scheduling commands in Linux?

        At,batch,nohup,kill,nice commands

  1. What is the difference between foreground and background processes?

Foreground and background processes. Processes that require a user to start them or to interact with them are called foreground processes. Processes that are run independently of a user are referred to as background processes. Programs and commands run as foreground processes by default.

          bg : put the recently suspended process in the background. … fg : put the recently     suspended process in the foreground. & : run a program in the background to begin with. jobs : list child processes under terminal shell.

  1. Write a program to find the largest of two numbers.

        echo "Enter Num1"

read num1

echo "Enter Num2"

read num2

 

if [ $num1 -gt $num2 ]

then

    echo $num1

else

    echo $num2

fi


  1. Write syntax of case statement in Linux. Write one example program using case statement.

case command in Linux is the best alternative when we had to use multiple if/elif on a single variable. It is used to execute the commands based on the pattern matching.

            case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac

          Example program

  1. Explain different operators in shell programming.


   Shell is an interface using which the programmer can execute command and interact directly to the operating system. Shell scripting is giving commands that a shell can execute.

In shell also there are variables and operators that are used to manipulate these variables. There are 5 basic operators in shell scripting.

  • Arithmetic Operators

  • Relational Operators

  • Boolean Operators

  • Bitwise Operators

  • File Test Operators

Arithmetic Operators

Arithmetic operators in shell scripting are used to perform general arithmetic/ mathematical operations. There are 7 valid arithmetic operators in shell scripting

  • Addition (+) is used to add two operands (variables).

  • Subtraction (-) is used to subtract two variables (operands) in shell scripting.

  • Multiplication (*) is used to multiply two variables (operands) in shell scripting.

  • Division (/) is used to divide two variables (operands) in shell scripting.

  • Modulus (%) is used to find the remainder on division of operands in shell scripting.

  • Increment operator (++) is used to add one to the current value of the operator.

  • Decrement operator (--) is used to subtract one from the current value of the operator.

Relational Operator

The relational operator in shell scripting defines the relations between operands. The return value of these are either true or false depending on the operator and operands. There are 6 types of valid relational operators in shell scripting

  • == operator is the operator that equates the values of two operators. It returns true if the values are equal and returns false otherwise.

  • != operator is the operator that equates the values of two operators and check for their inequality. It returns true if the values are not equal and returns false otherwise.

  • < operator is the less than operator comparing the values of two operators. If first operend’s value is smaller than seconds one then operator returns true otherwise returns false.

  • <= operator is less than or equal to operator that compares the values of two operators. If first operend’s value is smaller than or equal to seconds one then operator returns true otherwise returns false.

  • >operator is the greater than operator comparing the values of two operators. If first operend’s value is larger than seconds one then operator returns true otherwise returns false.

  • >= operator is greater than or equal to operator that compares the values of two operators. If first operend’s value is larger than or equal to seconds one then operator returns true otherwise returns false.

Boolean operator

Boolean operator also known as logical operators are used to perform logical operations in shell scripting. There are 3 types of valid logical operators in shell scripting

  • Logical AND (&&) calculates the logic AND of the value that boolean. It returns true if both operands are true, otherwise false.

  • Logical OR (||) calculates logical OR operation of boolean operands. It returns false if both operands are false otherwise true.

  • Logical Not Equal to (!) calculates the negation of the single operator passed. If the value of operand is true it returns false otherwise true

Bitwise operator are the operators that perform bitwise operations on bit variables. There are 6 types of bitwise operators in shell scripting

  • Bitwise AND (&) is the operator that does the binary AND operation on the bits of the operands i.e. each bit of first variable is operated with respective bit of second operator.

  • Bitwise OR (|) is the operator that does the binary OR operation on the bits of the operands i.e. each bit of first variable is operated with respective bit of second operator.

  • Bitwise XOR (^) is the operator that does the binary XOR operation on the bits of the operands i.e. each bit of first variable is operated with respective bit of second operator.

  • Bitwise complement (~) is the operator that does the binary NOT operation on the bits of the operands i.e. each bit of first variable is operated with respective bit of second operator.

  • Bitwise Left Shift (<<) is the operator that shifts the bits of the operand to the left by n times specified at the right of the operator.

  • Bitwise Left Shift (>>) is the operator that shifts the bits of the operand to the right by n times specified at the right of the operator.

File Test Operator

The file test operators are used to test particular properties of the file. Some of the file test operators are :

  • -b operator is used to check if the specified file is a block special file or not. If the file is a block special file then the function returns true otherwise returns false.

  • -s operator is the operator that is used to check the size of the given file. If the file size is greater than 0, it returns true otherwise returns false.

  • -r operator is the operators that check if the access to read file contents is granted or not. If read access is granted than it returns true otherwise false.

  • -w operator is the operators that check if the access to write into file is granted or not. If write access is granted than it returns true otherwise false.

  • -x operator is the operators that check if the access to execute the file is granted or not. If execution access is granted than it returns true otherwise false.


19.   Write a note on log and configuration files.

  • Linux keep track of itself.Linux files are grouped according to their functionality and usage,so there are separate directories for configuration and log files.  

  • It will keep the log file to store the data of logins and the root user can monitor the system to see if people are trying to access the computer illegally.

  • Configuration files on a Linux system that control user permissions,system applications,daemons,services,and other administrative tasks in a multi-user,multi-tasking environment.

  • Log files are files that contain message about the system,including the kernel,services, and applications running on it.

  • /var/log

  • /etc 

20.  What are the roles of system administrator?

        There are some of the things that a Linux system administrator should know and understand:

  • Linux File Systems

  • File System Hierarchy

  • Managing Root/super User

  • Basic Bash Command

  • Handling File, Directories and Users

 

Below are some duties of a Linux Administrator:

  • Maintain all internet requests inclusive to DNS, RADIUS, Apache, MySQL, PHP.

  • Taking regular back up of data, create new stored procedures and listing back-up is one of the duties.

  • Analyzing all error logs and fixing along with providing excellent customer support for Webhosting, ISP and LAN Customers on troubleshooting increased support troubles.

  • Communicating with the staff, vendors, and customers in a cultivated, professional manner at all times has to be one of his characteristics.

  • Enhance, maintain and creating the tools for the Linux environment and its users.

  • Detecting and solving the service problems ranging from disaster recovery to login problems.

  • Installing the necessary systems and security tools. Working with the Data Network Engineer and other personnel/departments to analyze hardware requirements and makes acquiring recommendations.

  • Troubleshoot, when the problem occurs in the server.

 

21. Explain different filter commands in Linux.

  • Pr,head,tail,sort,uniq,tr,cut,grep,egrep,sed

  • Explain each with its options

(4 x 8 = 32 Marks)


Section C

Answer up to 3 questions carrying 15 marks each. However, total marks for this section should not exceed 30 marks. Marks scored over 30 will be ignored


22. What are the features and advantages of Linux Operating system?

Linux is the best-known and most-used open-source operating system. As an operating system, Linux sits underneath all of the other software on a computer. It receives requests from those programs and then relays those requests to the computer’s hardware.

     1. Open Source

As it is open-source, its source code is easily available. Anyone having programming knowledge can customize the operating system. One can contribute, modify, distribute, and enhance the code for any purpose.

2. Security

The Linux security feature is the main reason that it is the most favorable option for developers. It is not completely safe, but it is less vulnerable than others. Each application needs to authorize by the admin user. The virus is not executed until the administrator provides the access password. Linux systems do not require any antivirus program.

3. Free

Certainly, the biggest advantage of the Linux system is that it is free to use. We can easily download it, and there is no need to buy the license for it. It is distributed under GNU GPL (General Public License). Comparatively, we have to pay a huge amount for the license of the other operating systems.

4. Lightweight

Linux is lightweight. The requirements for running Linux are much less than other operating systems. In Linux, the memory footprint and disk space are also lower. Generally, most of the Linux distributions required as little as 128MB of RAM around the same amount for disk space.

5. Stability

Linux is more stable than other operating systems. Linux does not require to reboot the system to maintain performance levels. It rarely hangs up or slow down. It has big up-times.

6. Performance

Linux system provides high performance over different networks. It is capable of handling a large number of users simultaneously.

7. Flexibility

Linux operating system is very flexible. It can be used for desktop applications, embedded systems, and server applications too. It also provides various restriction options for specific computers. We can install only necessary components for a system.

8. Software Updates

In Linux, the software updates are in user control. We can select the required updates. There a large number of system updates are available. These updates are much faster than other operating systems. So, the system updates can be installed easily without facing any issue.

9. Distributions/ Distros

There are many Linux distributions available in the market. It provides various options and flavors of Linux to the users. We can choose any distros according to our needs. Some popular distros are Ubuntu, Fedora, Debian, Linux Mint, Arch Linux, and many more.

For the beginners, Ubuntu and Linux Mint would be useful and, Debian and Fedora would be good choices for proficient programmers.

10. Live CD/USB

Almost all Linux distributions have a Live CD/USB option. It allows us to try or run the Linux operating system without installing it.

11. Graphical User Interface

Linux is a command-line based OS but, it provides an interactive user interface like Windows.

12. Suitable for programmers

It supports almost all of the most used programming languages such as C/C++JavaPythonRuby, and more. Further, it offers a vast range of useful applications for development.

The programmers prefer the Linux terminal over the Windows command line. The package manager on Linux system helps programmers to understand how things are done. Bash scripting is also a functional feature for the programmers. It also provides support for SSH, which helps in managing the servers quickly.

13. Community Support

Linux provides large community support. We can find support from various sources. There are many forums available on the web to assist users. Further, developers from the various opensource communities are ready to help us.

14. Privacy

Linux always takes care of user privacy as it never takes much private data from the user. Comparatively, other operating systems ask for the user's private data.

15. Networking

Linux facilitates with powerful support for networking. The client-server systems can be easily set to a Linux system. It provides various command-line tools such as ssh, ip, mail, telnet, and more for connectivity with the other systems and servers. Tasks such as network backup are much faster than others.

16. Compatibility

Linux is compatible with a large number of file formats as it supports almost all file formats.

17. Installation

Linux installation process takes less time than other operating systems such as Windows. Further, its installation process is much easy as it requires less user input. It does not require much more system configuration even it can be easily installed on old machines having less configuration.

18. Multiple Desktop Support

Linux system provides multiple desktop environment support for its enhanced use. The desktop environment option can be selected during installation. We can select any desktop environment such as GNOME (GNU Network Object Model Environment) or KDE (K Desktop Environment) as both have their specific environment.

19. Multitasking

It is a multitasking operating system as it can run multiple tasks simultaneously without affecting the system speed.

20. Heavily Documented for beginners

There are many command-line options that provide documentation on commands, libraries, standards such as manual pages and info pages. Also, there are plenty of documents available on the internet in different formats, such as Linux tutorials, Linux documentation project, Serverfault, and more. To help the beginners, several communities are available such as Ask Ubuntu, Reddit, and StackOverflow.

Basic Features

Following are some of the important features of Linux Operating System.

  • Portable  Portability means software can works on different types of hardware in same way. Linux kernel and application programs supports their installation on any kind of hardware platform.

  • Open Source  Linux source code is freely available and it is community based development project. Multiple teams work in collaboration to enhance the capability of Linux operating system and it is continuously evolving.

  • Multi-User  Linux is a multiuser system means multiple users can access system resources like memory/ ram/ application programs at same time.

  • Multiprogramming  Linux is a multiprogramming system means multiple applications can run at same time.

  • Hierarchical File System  Linux provides a standard file structure in which system files/ user files are arranged.

  • Shell  Linux provides a special interpreter program which can be used to execute commands of the operating system. It can be used to do various types of operations, call application programs. etc.

  • Security  Linux provides user security using authentication features like password protection/ controlled access to specific files/ encryption of data.


23.  Explain Linux processes.

    An instance of a running program is called a process. Every time you run a shell command, a program is run and a process is created for it. Each process in Linux has a process id (PID) and it is associated with a particular user and group account.

Linux is a multitasking operating system, which means that multiple programs can be running at the same time (processes are also known as tasks). Each process has the illusion that it is the only process on the computer. The tasks share common processing resources (like CPU and memory).

  A process can be run in two ways:  

 

  Foreground Process : Every process when started runs in foreground by default, receives input from the keyboard, and sends output to the screen.  When issuing pwd command 

 

$ ls pwd


When a command/process is running in the foreground and is taking a lot of time, no other processes can be run or started because the prompt would not be available until the program finishes processing and comes out. 


Background Process:


It runs in the background without keyboard input and waits till keyboard input is required. Thus, other processes can be done in parallel with the process running in the background since they do not have to wait for the previous process to be completed. 
Adding & along with the command starts it as a background process 


$ pwd &


Tracking ongoing processes

ps (Process status) can be used to see/list all the running processes. 

$ ps


PID       TTY      TIME        CMD

19        pts/1    00:00:00    sh

24        pts/1    00:00:00    ps

For more information -f (full) can be used along with ps  

$ ps –f


UID      PID  PPID C STIME    TTY        TIME CMD

52471     19     1 0 07:20    pts/1  00:00:00f     sh

52471     25    19 0 08:04    pts/1  00:00:00      ps -f

For single-process information, ps along with process id is used  

$ ps 19


PID       TTY      TIME        CMD

19        pts/1    00:00:00    sh

For a running program (named process) Pidof finds the process id’s (pids) 
Fields described by ps are described as: 

  • UID: User ID that this process belongs to (the person running it)

  • PID: Process ID

  • PPID: Parent process ID (the ID of the process that started it)

  • C: CPU utilization of process

  • STIME: Process start time

  • TTY: Terminal type associated with the process

  • TIME: CPU time is taken by the process

  • CMD: The command that started this process

There are other options which can be used along with ps command : 

  • -a: Shows information about all users

  • -x: Shows information about processes without terminals

  • -u: Shows additional information like -f option

  • -e: Displays extended information

Stopping a process:
When running in foreground, hitting Ctrl + c (interrupt character) will exit the command. For processes running in background kill command can be used if it’s pid is known. 




$ ps –f


UID      PID  PPID C STIME    TTY        TIME CMD

52471     19     1 0 07:20    pts/1  00:00:00      sh

52471     25    19 0 08:04    pts/1  00:00:00      ps –f


$ kill 19

Terminated

If a process ignores a regular kill command, you can use kill -9 followed by the process ID. 

$ kill -9 19

Terminated

Other process commands:

bg: A job control command that resumes suspended jobs while keeping them running in the background 
Syntax:

bg [ job ]

For example: 

bg %19

fg: It continues a stopped job by running it in the foreground. 
Syntax:  

fg [ %job_id ]

For example  

fg 19

top: This command is used to show all the running processes within the working environment of Linux. 
Syntax:  

top

nice: It starts a new process (job) and assigns it a priority (nice) value at the same time. 
Syntax:  

nice [-nice value] 

nice value ranges from -20 to 19, where -20 is of the highest priority. 

renice : To change the priority of an already running process renice is used. 
Syntax:  

renice [-nice value] [process id]

df: It shows the amount of available disk space being used by file systems 
Syntax:  

df

Output:  

Filesystem     1K-blocks      Used Available Use% Mounted on

/dev/loop0      18761008  15246876   2554440  86% /

none                   4         0         4   0% /sys/fs/cgroup

udev              493812         4    493808   1% /dev

tmpfs             100672      1364     99308   2% /run

none                5120         0      5120   0% /run/lock

none              503352      1764    501588   1% /run/shm

none              102400        20    102380   1% /run/user

/dev/sda3      174766076 164417964  10348112  95% /host

free: It shows the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel 
Syntax:  

free

Output:  

             total       used       free     shared    buffers     cached

Mem:       1006708     935872      70836          0     148244     346656

-/+ buffers/cache:     440972     565736

Swap:       262140     130084     132056

Types of Processes

  1. Parent and Child process : The 2nd and 3rd column of the ps –f command shows process id and parent’s process id number. For each user process, there’s a parent process in the system, with most of the commands having shell as their parent.

  2. Zombie and Orphan process : After completing its execution a child process is terminated or killed and SIGCHLD updates the parent process about the termination and thus can continue the task assigned to it. But at times when the parent process is killed before the termination of the child process, the child processes become orphan processes, with the parent of all processes “init” process, becomes their new pid. 
    A process which is killed but still shows its entry in the process status or the process table is called a zombie process, they are dead and are not used.

  3. Daemon process : They are system-related background processes that often run with the permissions of root and services requests from other processes, they most of the time run in the background and wait for processes it can work along with for ex print daemon. 
    When ps –ef is executed, the process with ? in the tty field are daemon processes.

 

24.  Explain different looping and branching statements in shell programming.

  • Looping Statements in Shell Scripting: There are total 3 looping statements which can be used in bash programming

  1. while statement

  2. for statement

  3. until statement

      To alter the flow of loop statements, two commands are used they are,

  1. break

  2. continue

  • Branching Statements 

The if Statement

The case statement

  • Explanation of each with syntax and its example


25.  Explain different servers in Linux.

  • A server is computer that provides data to other computers.

  • DHCP, DNS,SQUID, Apache, Telnet, FTP, Samba

  • Describe each with any 3 advantages and disadvantages.

(Maximum 30 Marks)




Comments

Popular posts from this blog

UG, S1 BCA, First internal examination, Introduction to Problem Solving and Web Designing, September 2024