Linux Interview Questions & Answers

Linux Interview questions

Linux Interview Questions

  1. Question1. What Is Linux Shell?

    Answer :

    Linux shell is a user interface used for executing the commands. Shell is a program the user uses for executing the commands. In UNIX, any program can be the users shell. Shell categories in Linux are:
    Bourne shell compatible, C shell compatible, nontraditional, and historical.

  2. Question2. What Is Shell Script?

    Answer :

    A shell script, as the name suggests, is a script written for the shell. Script here means a programming language used to control the application. The shell script allows different commands entered in the shell to be executed. Shell script is easy to debug, quicker as compared to writing big programs. However the execution speed is slow because it launches a new process for every shell command executed. Examples of commands are cp, cn, cd.

  3. Question3. What Is Kernel? Explain The Task It Performs.

    Answer :

    Kernel is used in UNIX like systems and is considered to be the heart of the operating system. It is responsible for communication between hardware and software components. It is primarily used for managing the systems resources as well.

    Kernel Activities:

    The Kernel task manager allows tasks to run concurrently.

    Managing the computer resources: Kernel allows the other programs to run and use the resources.

    Resources include i/o devices, CPU, memory.

    Kernel is responsible for Process management. It allows multiple processes to run simultaneously allowing user to multitask.

    Kernel has an access to the systems memory and allows the processes to access the memory when required.

    Processes may also need to access the devices attached to the system. Kernel assists the processes in doing so.

    For the processes to access and make use of these services, system calls are used.

  4. Question4. What Are Pipes?

    Answer :

    A pipe is a chain of processes so that output of one process (stdout) is fed an input (stdin) to another. UNIX shell has a special syntax for creation of pipelines. The commands are written in sequence separated by |. Different filters are used for Pipes like AWK, GREP.
    e.g. sort file | lpr ( sort the file and send it to printer)

  5. Question5. Explain Trap Command; Shift Command, Getopts Command Of Linux

    Answer :

    Trap command: controls the action to be taken by the shell when a signal is received.
    Trap [OPTIONS] [ [arg] signspec..]
    Arg is the action to be taken or executed on receiving a signal specified in signspec.
    e.g. trap “rm $FILE; exit” // exit (signal) and remove file (action).

    Shift Command: Using shift command, command line arguments can be accessed. The command causes the positional parameters shift to the left. Shift [n] where n defaults to 1. It is useful when several parameters need to be tested.

    Getopts command: this command is used to parse arguments passed. It examines the next command line argument and determines whether it is a valid option.

    Getopts {optstring} {variable1}. Here, optsring contains letters to be recognized if a letter is followed by a colon, an argument should be specified. E.g (whether the argument begins with a minus sign and is followed by any single letter contained inside options ) If not, diagnostic messages are shown. It is usually executed inside a loop.

  6. Question6. What Stateless Linux Server? What Feature It Offers?

    Answer :

    A stateless Linux server is a centralized server in which no state exists on the single workstations. There may be scenarios when a state of a partilcuar system is meaningful (A snap shot is taken then) and the user wants all the other machines to be in that state. This is where the stateless Linux server comes into picture.

    It stores the prototypes of every machine.
    It stores snapshots taken for those systems.
    It stores home directories for those system.

    Uses LDAP containing information of all systems to assist in finding out which snapshot (of state) should be running on which system.

  7. Question7. What Does Nslookup Do? Explain Its Two Modes.

    Answer :

    Nslookup is used to find details related to a Domain name server. Details like IP addresses of a machine, MX records, servers etc. It sends a domain name query packet to the corresponding DNS.

    Nslookup has two modes. Interactive and non interactive. Interactive mode allows the user to interact by querying information about different hosts and domains.

    Non interactive mode is used to fetch information about the specified host or domain.

    Interactive mode:
    Nslookup [options] [server]

  8. Question8. What Is Bash Shell?

    Answer :

    Bash is a free shell for UNIX. It is the default shell for most UNIX systems. It has a combination of the C and Korn shell features. Bash shell is not portable. any Bash-specific feature will not function on a system using the Bourne shell or one of its replacements, unless bash is installed as a secondary shell and the script begins with #!/bin/bash. It supports regular and expressions. When bash script starts, it executes commands of different scripts.

  9. Question9. What Are The Process States In Linux?

    Answer :

    Process states in Linux:
    Running: Process is either running or ready to run.

    Interruptible: a Blocked state of a process and waiting for an event or signal from another process.

    Uninterruptible:- a blocked state. Process waits for a hardware condition and cannot handle any signal.

    Stopped: Process is stopped or halted and can be restarted by some other process.

    Zombie: process terminated, but information is still there in the process table.

  10. Question10. What Is A Zombie?

    Answer :

    Zombie is a process state when the child dies before the parent process. In this case the structural information of the process is still in the process table. Since this process is not alive, it cannot react to signals. Zombie state can finish when the parent dies. All resources of the zombie state process are cleared by the kernel.

  11. Question11. Explain Each System Calls Used For Process Management In Linux.

    Answer :

    System calls used for Process management:
    Fork () :- Used to create a new process
    Exec() :- Execute a new program
    Wait():- wait until the process finishes execution
    Exit():- Exit from the process
    Getpid():- get the unique process id of the process
    Getppid():- get the parent process unique id
    Nice():- to bias the existing property of process

  12. Question12. How Do You List Files In A Directory?

    Answer :

    ls - list directory contents
    ls -l (-l use a long listing format)

  13. Question13. How Do You List All Files In A Directory, Including The Hidden Files?

    Answer :

    ls -a (-a, do not hide entries starting with .)

  14. Question14. How Do You Find Out All Processes That Are Currently Running?

    Answer :

    ps -f (-f does full-format listing.)

  15. Question15. How Do You Find Out The Processes That Are Currently Running Or A Particular User?

    Answer :

    ps -au Myname (-u by effective user ID (supports names)) (a - all users)

  16. Question16. How Do You Kill A Process?

    Answer :

    kill -9 8 (process_id 8) or kill -9 %7 (job number 7)
    kill -9 -1 (Kill all processes you can kill.)
    killall - kill processes by name most (useful - killall java)

  17. Question17. What Would You Use To Edit Contents Of The File?

    Answer :

    vi screen editor or jedit, nedit or ex line editor

  18. Question18. What Would You Use To View Contents Of A Large Error Log File?

    Answer :

    tail -10 file_name ( last 10 rows)

  19. Question19. How Do You Log In To A Remote Unix Box?

    Answer :

    Using telnet server_name or ssh -l ( ssh - OpenSSH SSH client (remote login program))

  20. Question20. How Do You Get Help On A Unix Terminal?

    Answer :

    man command_name
    info command_name (more information)

Introduction The Linux Tcp/ip Source Code A Brief History Of Data Communication The Osi Seven-layer Network Model Connection-oriented And Connectionless Protocols Broadband Networking Versus Local Area Networking Packets And Frames The Digital Data Rate Hierarchy In The Public Network Broadband Networking Protocols Of Yesterday And Today What Is Connection-oriented And Connectionless Protocols Difference Between Broadband Networking Versus Local Area Networking Asynchronous Versus Synchronous Data Transmission Synchronous Data Transmission X.25 High Level Data Link Protocol Sliding Windows Hdlc As Used In Point-to-point Protocol Frame Relay Bearer Service Asynchronous Transmission Mode (atm) Tcp/ip In Embedded Systems A Note On Tcp/ip Implementation Tcp/ip In Terms Of The Osi Model Physical Layer Data Link Layer Layer 3, The Network Layer--ip Layer 4, The Transport Layer Sockets--the Transport Layer Interface Application Layer Protocols Tcp/ip In Embedded Systems Tcp/ip Standards, Numbers, And Practical Considerations Linux Networking Interfaces And Device Drivers Network Interface Devices The Network Device Structure, Net_device Network Device Initialization Device Discovery And Dynamic Network Interface Driver Initialization Network Interface Registration Network Interface Driver Service Functions Receiving Packets Transmitting Packets Notifier Chains And Network Interface Device Status Notification Linux Sockets What Is A Socket? Socket, Sock, And Other Data Structures For Managing Sockets Socket Layer Initialization Family Values And The Protocol Switch Table The Socket Application Programming Interface Packet, Raw, Netlink, And Routing Sockets Security And Linux Capabilities A Note About The Socket Api And Ipv6 Implementation Of The Socket Api System Calls Creation Of A Socket Io System Calls And Sockets Netlink And Rtnetlink The Linux Tcp/ip Stack Packet Handler Glue Linux Tcp/ip Stack Initialization Kernel Threading Packet Queuing Layer And Queuing Disciplines Receiving Packets In Packet Queuing Layer, Net_rx_softirq Transport Layer De-multiplexing And Internal Packet Routing Cache Rich In_device Structure For Ipv4 Address Assignment, Multicast, And Configuration Security, Stackable Destination, And Xfrm Some Practical Considerations Socket Buffers And Linux Memory Allocation Heap-based Memory Allocation Pre-allocated Fixed-sized Buffers Mbufs In Bsd 4.4 Slab Allocation Linux Slab Allocator Linux Socket Buffers Socket Buffers, Fragmentation And Segmentation Socket Buffer Allocation And Lists Socket Buffer Utility Functions Slab Caches Sending The Data From The Socket Through Udp And Tcp Socket Layer Glue Transport Layer Socket Initialization Initiating A Connection Sending Data From A Socket Via Udp Sending Data From A Socket Via Tcp Tcp Output Some Key Tcp Data Structures Tcp Timers The Network Layer, Ip Routing Theory Ipv4 Routing, Routing Cache, And The Routing Policy Database Ip Protocol Initialization The Route Cache The Rpdb, The Fib, And The Fib Rules Routing Input Packets Routing Output Packets Internet Peers And The Inet_peer Structure The Address Resolution Protocol The Internet Control Message Protocol Multicast And Igmp Sending Packets From Ip Receiving Packets In Ip Receiving Data In The Transport Layer, Udp, And Tcp Receive-side Packet Handling Receiving A Packet In Udp Udp Socket-level Receive Receiving Data In Tcp Tcp Receive State Processing Tcp Processing Data Segments In Established State Tcp Time_wait State Tcp Socket-level Receive Internet Protocol Version 6 (ipv6) Facilities In Ipv6 Ipv6 Addressing Ipv6 Packet Format Ipv6 Implementation In Linux Ipv6 Socket Implementation Ipv6 Fragmentation And De-fragmentation Implementation Ipv6 Output Ipv6 Input Ipv6 Udp Ipv6 Tcp Icmpv6 Neighbor Discovery Multicasting And The Multicast Listener Discovery (mld) Protocol For Ipv6 Auto Configuration Routing And The Ipv6 Fib Linux Interview Questions Linux Practice Tests