Login linux terminal pwd ls useradd commands accessing virtual terminals
In this assignment I will instruct you about some basic commands of Linux. You will get seven virtual terminal when you perform full installations. Although you can use graphics for daily task but here we are preparing for RHCE exam so you must use command line interface. Because all question are based on command line in RHCE Exam.
Virtual Consoles
A virtual console is a command line where you can log into and control Linux. As RHEL is a multi terminal operating system, you can log into Linux, even with the same user ID, several times. It's easy to open a new virtual console. Just use the appropriate ALT-function key combination. For example, pressing ALT-F2 brings you to the second virtual console. You can switch between adjacent virtual consoles by pressing ALT-RIGHT ARROW or ALT-LEFT ARROW. For example, to move from virtual console 2 to virtual console 3, press ALT-RIGHT ARROW.
You can switch between virtual terminals by just press the ALT+CTRL+Funcation key combinations.
ALT + CTRL + F1 for terminal 1 ALT + CTRL + F2 for terminal 2 ALT + CTRL + F3 for terminal 3 ALT + CTRL + F4 for terminal 4 ALT + CTRL + F5 for terminal 5 ALT + CTRL + F6 for terminal 6 ALT + CTRL + F7 for terminal 7
Terminal 7 is by default graphic mode beside it all six terminal are CLI based. Open any terminial by press ALT+CTRL+F1 key combinations. root account is automatically created when we install Linux.
Type root on login name and press enter key, now give password ( no asterisk character like window to guess the password length) When you login from root account you will get # sign at command prompt , and when you login from normal user you will get $ prompt.
#clear
This command is used to clear the screen.You have three options to logout .
Press CTRL+D #exit #logout
All three commands perform same task.
#pwd /root
Print working directory command will tell you about current location from / partition.
#ls
ls command will list the object in directory. All directory are listed in blue color while files are shown white color.
#ls –a
Normal ls command will not list the hidden files. If you want to list the hidden file use –a switch with ls command to list the hidden files.
#ls –l
Ls command with –l switch will list the objects in long formats . we will discuss more about –l switch in coming sections.
#ll
Same as ls –l . First and major task for any system administrator is user managements. For testing purpose you can perform all task with root account but in real life root account is used for administrative purpose only. Lest create a normal user account for further practical.
#useradd [user name ]
Useradd command is used to create user. Several advance options are used with useradd command but you will learn about them in coming article.
#passwd [user name]
In linux no user can be login without password. passwd command is used to assign password for any user. Do not execute this command without user name otherwise it will change root password.
Everything in Linux can be reduced to a file. Partitions are associated with files such as /dev/hda1. Hardware components are associated with files such as /dev/modem. Detected devices are documented as files in the /proc directory. The Filesystem Hierarchy Standard (FHS) is the official way to organize files in Unix and Linux directories.
Linux/Unix Filesystems and Directories
Several major directories are associated with all modern Unix/Linux operating systems. These directories organize user files, drivers, kernels, logs, programs, utilities, and more into different categories. The standardization of the FHS makes it easier for users of other Unix-based operating systems to understand the basics of Linux. Every FHS starts with the root directory, also known by its label, the single forward slash (/). All of the other directories shown in Table are subdirectories of the root directory. Unless they are mounted separately, you can also find their files on the same partition as the root directory.
/
The root directory, the top-level directory in the FHS. All other directories are subdirectories of root, which is always mounted on some partition. All directories that are not mounted on a separate partition are included in the root directory?s partition.
/bin
Essential command line utilities. Should not be mounted separately; otherwise, it could be difficult to get to these utilities when using a rescue disk.
/boot
Includes Linux startup files, including the Linux kernel. Can be small; 16MB is usually adequate for a typical modular kernel. If you use multiple kernels, such as for testing a kernel upgrade, increase the size of this partition accordingly.
/etc
Most basic configuration files.
/dev
Hardware and software device drivers for everything from floppy drives to terminals. Do not mount this directory on a separate partition.
/home
Home directories for almost every user.
/lib
Program libraries for the kernel and various command line utilities. Do not mount this directory on a separate partition.
/mnt
The mount point for removable media, including floppy drives, CD-ROMs, and Zip disks.
/opt
Applications such as WordPerfect or StarOffice.
/proc
Currently running kernel-related processes, including device assignments such as IRQ ports, I/O addresses, and DMA channels.
/root
The home directory of the root user.
/sbin
System administration commands. Don't mount this directory separately.
/tmp
Temporary files. By default, Red Hat Linux deletes all files in this directory periodically.
/usr
Small programs accessible to all users. Includes many system administration commands and utilities.
/var
Variable data, including log files and printer spools.
Types of Files Used by Linux
When working with Linux, you need to be aware of the fact that there are a number of different file types used by the file system. This is another area where the Linux file system differs significantly from the Windows file system. With a Windows file system you basically have two entry types in the file system:
Directories
Files
Granted, you can have normal files, hidden files, shortcut files, word processing files, executable files, and so on. However, these are all simple variations of the basic file when working with Windows. With Linux, however, there are a variety of different file types used by the file system. These include the file types shown in Table
File Type
Description
Regular files
These files are similar to those used by the file systems of other operating systems—for example, executable files, OpenOffice.org files, images, text configuration files, etc.
Links
These files are pointers that point to other files in the file system.
FIFOs
FIFO stands for First In First Out. These are special files used to move data from one running process on the system to another. A FIFO file is basically a queue where the first chunk of data added to the queue is the first chunk of data removed from the queue. Data can only move in one direction through a FIFO.
Sockets
Sockets are similar to FIFOs in that they are used to transfer information between sockets. With a socket, however, data can move bi-directionally.
Some of the Configuration Files in /etc Directory that you should remember
File
Function
/etc/fstab
Lists the partitions and file systems that will be automatically mounted when the system boots.
/etc/group
Contains local group definitions.
/etc/grub.conf
Contains configuration parameters for the GRUB bootloader (assuming it’s being used on the system).
/etc/hosts
Contains a list of hostname-to-IP address mappings the system can use to resolve hostnames.
/etc/inittab
Contains configuration parameters for the init process.
/etc/init.d/
A subdirectory that contains startup scripts for services installed on the system. On a Fedora or Red Hat system, these are located in /etc/rc.d/init.d.
/etc/modules.conf
Contains configuration parameters for your kernel modules.
/etc/passwd
Contains your system user accounts.
/etc/shadow
Contains encrypted passwords for your user accounts.
use standard command line tools (e.g., ls, cp, mv, rm, tail, cat, etc.) to create, remove, view, and investigate files and directories
use grep, sed, and awk to process text streams and files
use a terminal-based text editor, such as vim or nano, to modify text files
use input/output redirection
understand basic principles of TCP/IP networking, including IP addresses, netmasks, and gateways for IPv4 and IPv6
use su to switch user accounts
use passwd to set passwords
use tar, gzip, and bzip2
configure an email client on Red Hat Enterprise Linux
use text and/or graphical browser to access HTTP/HTTPS URLs
use lftp to access FTP URLs
RHCT skills
Troubleshooting and System Maintenance
RHCTs should be able to:
boot systems into different run levels for troubleshooting and system maintenance
diagnose and correct misconfigured networking
diagnose and correct hostname resolution problems
configure the X Window System and a desktop environment
add new partitions, filesystems, and swap to existing systems
use standard command-line tools to analyze problems and configure system
Installation and Configuration
RHCTs must be able to:
perform network OS installation
implement a custom partitioning scheme
configure printing
configure the scheduling of tasks using cron and at
attach system to a network directory service, such as NIS or LDAP
configure autofs
add and manage users, groups, quotas, and File Access Control Lists
configure filesystem permissions for collaboration
install and update packages using rpm
properly update the kernel package
configure the system to update/install packages from remote repositories using yum or pup
modify the system bootloader
implement software RAID at install-time and run-time
use /proc/sys and sysctl to modify and set kernel run-time parameters
use scripting to automate system maintenance tasks
configure NTP for time synchronization with a higher-stratum server
RHCE skills
Troubleshooting and System Maintenance
RHCEs must demonstrate the RHCT skills listed above, and should be able to:
use the rescue environment provided by first installation CD
diagnose and correct boot failures arising from bootloader, module, and filesystem errors
diagnose and correct problems with network services (see Installation and Configuration below for a list of these services)
add, remove, and resize logical volumes
diagnose and correct networking services problems where SELinux contexts are interfering with proper operation.
Installation and Configuration
RHCEs must demonstrate the RHCT-level skills listed above, and they must be capable of configuring the following network services:
HTTP/HTTPS
SMB
NFS
FTP
Web proxy
SMTP
IMAP, IMAPS, and POP3
SSH
DNS (caching name server, slave name server)
NTP
For each of these services, RHCEs must be able to:
install the packages needed to provide the service
configure SELinux to support the service
configure the service to start when the system is booted
configure the service for basic operation
Configure host-based and user-based security for the service
RHCEs must also be able to:
configure hands-free installation using Kickstart
implement logical volumes at install-time
use iptables to implement packet filtering and/or NAT
use PAM to implement user-level restrictions
Based on this RHCE guide we have created step by step guide of RHCE exam. By our RHCE guide you can get your RHCE certificates. We have managed various practical example and suggest you to go through all these.
RHCE exam assesses the candidates ability to do the following:
* Install and configure Red Hat Linux * Configure file systems and networking * Configure X, the graphical user interface used on Unix and Linux systems * Configure basic security * Configure network services * Perform routine maintenance * Perform diagnostics and troubleshooting
Because Red Hat regularly updates its Linux distribution, RHCE certification is not valid indefinitely. However, according to Red Hat policy, RHCE certification remains valid for at least one year.
RHCE Courses and Exam
as part of its RHCE program, Red Hat offers several courses designed to prepare candidates for the RHCE exam. Candidates must take course RH302, which is the exam itself. However, candidates can take none, some, or all of the other courses. This section describes the RHCE courses offered by Red Hat, as well as the RH302 exam.
RH033: Introduction to Red Hat Linux I, II
RH033 is a four-day course intended for users who have no previous Unix or Linux experience. Students should, however, have previous experience with a computer, including use of a mouse and graphical user interface. Upon completion of the course, the student should be able to use and customize the GNOME desktop and be able to use the Linux command shell.
RH133: Red Hat Linux System Admin I, II
RH133 is a four-day course intended for users who are familiar with Red Hat Linux. Before taking this course, students should complete RH033 or possess equivalent experience. Upon completion of the course, students should be able to install and configure Red Hat Linux, X, and various network services and clients, such as DHCP, NIS, NFS, and Samba. Students should also be able to perform basic troubleshooting and rebuild the Linux kernel from source code.
RH253: Red Hat Linux Networking and Security Admin
RH253 is a four-day course intended for Unix or Linux system administrators. Before taking this course, students should complete RH133 or possess equivalent experience. Upon completion of the course, students should be able to install and configure network services such as Apache, DHCP, DNS, FTP, Samba, NFS, sendmail, and IMAP4/POP3 mail. Students should also be able to establish and administor a security policy that includes such elements as password security, kernel security, public/private key encryption, Kerberos, secure shell, and firewalls.
RH300: RHCE
RH300 is a five-day course that includes RH302, the RHCE exam, as an integral part of the course. Before taking this course, students should complete RH253 or possess equivalent experience and have experience as a Unix or Linux system or network administrator. The course consists of four days of instruction, and the fifth day is devoted to the RHCE exam. Upon completion of the course, students should be prepared to manage a Red Hat Linux system that offers common TCP/IP services, such as FTP and HTTP. The course includes eight units of instruction, each of which has one or more hands-on labs associated with the following topics:
* Hardware and Installation (x86 Architecture) * Configuration and Administration * Alternate Installation Methods * Kernel Services and Configuration * Standard Networking Services * X Window System * User and Host Security * Routers, Firewalls, Clusters, and Troubleshooting
RH302: RHCE Exam
Though styled by Red Hat as a course, RH302 is not a course in the ordinary sense of the word. Instead, RH302 is the RHCE exam, which has duration of one day. RH302 is the only course that RHCE candidates must take. The exam consists of the following three closed-book components:
Effective May 1, 2009, the RHCE exam is a single section lasting 3.5 hours. Previously, it had been two sections lasting a combined 5.5 hours. The content has be consolidated and reorganized into a single section in which time is used more efficiently. The RHCE exam consists of RHCT components (essentially the RHCT exam) plus RHCE-specific components. It is possible to earn RHCT in an RHCE exam if one has met the RHCT requirements but not the RHCE ones.
The components are not always presented in the same sequence. The course instructor, who acts as the exam proctor, will determine the sequence and announce it early in the day. The three components are equally weighted at 100 points each. The minimum passing score is 240 points, or 80 percent. However, a candidate must score at least 50 points (50 percent) on each exam component to pass the exam. Red Hat advises candidates of their exam scores by e-mail within 10 business days of taking the exam.
Practice
Because the RHCE exam is performance-based, it's crucial that you have, or develop, experience in working with Unix or Linux and related network services. This step by step guide is focus to get your RHCE certification by present practical exercises. These exercises can be time-consuming, and you may feel that they’re unnecessary. However, unless you have extensive practical experience, you should perform every exercise. Often, exercises will lead you to discover subtle points not evident merely from reading the exercise. If your practical experience with Unix and Linux is small, you should construct and perform your own additional exercises. The RHCE exam tests for the equivalent of about two years of experience with Linux and networking. With diligent effort, you can accumulate that experience in a matter of weeks. However, doing so will require that you skimp nowhere.
Sure Squid server is a popular open source GPLd proxy and web cache. It has a variety of uses, from speeding up a web server by caching repeated requests, to caching web, name server query , and other network lookups for a group of people sharing network resources. It is primarily designed to run on Linux / Unix-like systems. Squid is a high-performance proxy caching server for Web clients, supporting FTP, gopher, and HTTP data objects. Unlike traditional caching software, Squid handles all requests in a single, non-blocking, I/O-driven process. Squid keeps meta data and especially hot objects cached in RAM, caches DNS lookups, supports non-blocking DNS lookups, and implements negative caching of failed requests. Squid consists of a main server program squid, a Domain Name System lookup program (dnsserver), a program for retrieving FTP data (ftpget), and some management and client tools.
Squid Basic Configuration Squid configuration file located at /etc/squid/squid.conf. Open file using a text editor:
# vi /etc/squid/squid.conf
At least you need to define ACL (access control list) to work with squid. The defaults port is TCP 3128. Following example ACL allowing access from your local networks 192.168.1.0/24 and 192.168.2.0/24. Make sure you adapt to list your internal IP networks from where browsing should be allowed:
Answer
Linux is an operating system that uses UNIX like Operating system. However, unlike UNIX, Linux is an open source and free software. Linux was originally created by Linus Torvalds and commonly used in servers.
Popularity of Linux is because of the following reasons
It is free and open source. We can download Linux for free and customize it as per our needs.
It is very robust and adaptable.
Immense amount of libraries and utilities
What is LILO?
Answer LILO is Linux Loader is a boot loader for Linux. It is used to load Linux into the memory and start the Operating system. LILO can be configured to boot other operating systems as well. LILO is customizable, which means that if the default configuration is not correct, it can be changed. Config file for LILO is lilo.conf
What is the difference between home directory and working directory?
Answer Home directory is the default working directory when a user logs in. On the other hand, working directory is the user’s current directory. Working directory can be changed. It can be changed using cd command.
Home directory in Linux contains user’s personal data, configuration files, settings of a software etc. The content of home directory is private and the user has a complete control of it.
What is the difference between internal and external commands?
Answer Internal commands are commands that are already loaded in the system. They can be executed any time and are independent. On the other hand, external commands are loaded when the user requests for them. Internal commands don’t require a separate process to execute them. External commands will have an individual process. Internal commands are a part of the shell while external commands require a Path. If the files for the command are not present in the path, the external command won’t execute.
Explain the difference between a static library and a dynamic library?
Answer Static libraries are loaded when the program is compiled and dynamically-linked libraries are loaded in while the program is running. Dynamic libraries save the RAM space as against the static library because linking to static libraries includes the actual code for the library function(s)/procedure(s) with the executable. DLL code is kept at one location and is usually shared among all the processes that use the DLL.
What is LD_LIBRARY_PATH?
Answer LD_LIBRARY_PATH is an environment variable. It is used for debugging a new library or a non standard library. It is also used for which directories to search. Path to search for directories needs to given. The variable can be set by using setenv—LD_LIBRARY_PATH--$PATH
What is the file server in Linux server?
Answer
File server is used for file sharing. It enables the processes required fro sharing. All the files can be stored at a centralized location. Linux uses Samba to view the files on the server. Files on this server are backed up on a regular basis. Rights can be also assigned for the files on a file server.
What is NFS? What is its purpose?
Answer
NFS is Network File system. It is a file system used for sharing of files over a network. Other resources like printers and storage devices can also be shared. This means that using NFS files can be accessed remotely. Nfs command in linux can be used to achieve this.
Purpose of NFS:
NFS can be used for sharing of files remotely.
Data can be stored on a single machine and still remain accessible to others over the network.
Reduction of the number of removable media drives throughout the network since they can be shared.
How do I send email with linux?
Answer Email can be sent in Linux using the mail command.
Mail [options] [users]
Options include: -s for subject, -c for carbon copy, -b for blind carbon copy
E.g. mail user_name –s “hello”
Explain RPM (Red Hat Package Manager) features.
Answer
RPM is a package managing system (collection of tools to manage software packages).
Features:
RPM can verify software packages.
RPM can be served as a powerful search engine to search for software’s.
Components, software’s etc can be upgraded using RPM without having to reinstall them
Installing, reinstalling can be done with ease using RPM
During updates RPM handles configuration files carefully, so that the customization is not lost.
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.
What is Linux Shell? What is Shell Script?
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.
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.
What are Pipes? Explain use of 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)
Uses of Pipe
Several powerful functions can be in a single statement
Streams of processes can be redirected to user specified locations using >
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.
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.
Features:
It stores the prototypes of every machine
It stores snapshots taken for those systems
It stores home directories for those systems
Uses LDAP containing information of all systems to assist in finding out which snapshot (of state) should be running on which system.
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]
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.
Explain some Network-Monitoring Tools in Linux: ping, traceroute, tcpdump, ntop
Answer Network monitoring tools are used to monitor the network, systems present on the network, traffic etc.
Ping: Ping command is used to check if the system is in the network or not. To check if the host is operating.
e.g. ping ip_address
When the command is executed, it returns a detailed summary of the host. Packets sent, received, lost by estimating the round trip time.
Traceroute: the command is used to trace the path taken by the packet across a network. Tracing the path here means finding out the hosts visited by the packet to reach its destination. This information is useful in debugging. Roundtrip time in ms is shown for every visit to a host.
Tcpdump: commonly used to monitor network traffic. Tcdump captures and displays packet headers and matching them against criteria or all. It interprets Boolean operators and accepts host names, ip address, network names as arguments.
Ntop: Network top shows the network usage. It displays summary of network usage by machines on the network in a format as of UNIX top utility. It can also be run in web mode, which allows the display to be browsed with a web browser. It can display network traffic statistics, identify host etc. Interfaces are available to view such information.
How does the linux file system work?
Answer Linux file structure is a tree like structure. It starts from the root directory, represented by '/', and then expands into sub-directories. All the partitions are under the root directory. If a partition is mounted (The mount point defines the place of a particular data set in the file system) anywhere apart from a “device”, the system is not aware of the existence of that partition or device. Directories that are only one level below the root directory are often preceded by a slash, to indicate their position.
Explain file system of linux. The root "/" filesystem, /usr filesystem, /var filesystem, /home filesystem, /proc filesystem.
Answer Root "/" file system: The kernel needs a root file system to mount at start up. The root file system is generally small and should not be changed often as it may interrupt in booting. The root directory usually does not have the critical files. Instead sub directories are created. E.g. /bin (commands needed during bootup), /etc (config files) , /lib(shared libraries).
/usr filesystem : this file system is generally large as it contains the executable files to be shared amongst different machines. Files are usually the ones installed while installing Linux. This makes it possible to update the system from a new version of the distribution, or even a completely new distribution, without having to install all programs again. Sub directories include /bin, /include, /lib, /local (for local executables)
/var filesystem : this file system is specific to local systems. It is called as var because the data keeps changing. The sub directories include /cache/man (A cache for man pages), /games (any variable data belong to games), /lib (files that change), /log (log from different programs), /tmp (for temporary files)
/home filesystem: - this file system differs from host to host. User specific configuration files for applications are stored in the user's home directory in a file. UNIX creates directories for all users directory. E.g /home/my_name. Once the user is logged in ; he is placed in his home directory.
/proc filesystem : this file system does not exist on the hard disk. It is created by the kernel in its memory to provide information about the system. This information is usually about the processes. Contains a hierarchy of special files which represent the current state of the kernel .Few of the Directories include /1 (directory with information about process num 1, where 1 is the identification number), /cpuinfo (information about cpu), /devices (information about devices installed), /filesystem (file systems configured), /net (information about network protocols), /mem (memory usage)
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.
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
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
All devices are represented by files called special files that are located in/dev directory. Thus, device files and other files are named and accessed in the same way. A 'regular file' is just an ordinary data file in the disk. A 'block special file' represents a device with characteristics similar to a disk (data transfer in terms of blocks). A 'character special file' represents a device with characteristics similar to a keyboard (data transfer is by stream of bits in sequential order).
2. What is 'inode'?
All UNIX files have its description stored in a structure called 'inode'. The inode contains info about the file-size, its location, time of last access, time of last modification, permission and so on. Directories are also represented as files and have an associated inode. In addition to descriptions about the file, the inode contains pointers to the data blocks of the file. If the file is large, inode has indirect pointer to a block of pointers to additional data blocks (this further aggregates for larger files). A block is typically 8k.
Inode consists of the following fields:
File owner identifier
File type
File access permissions
File access times
Number of links
File size
Location of the file data
3.Brief about the directory representation in UNIX
·A Unix directory is a file containing a correspondence between filenames and inodes. A directory is a special file that the kernel maintains. Only kernel modifies directories, but processes can read directories. The contents of a directory are a list of filename and inode number pairs. When new directories are created, kernel makes two entries named '.' (refers to the directory itself) and '..' (refers to parent directory).
System call for creating directory is mkdir (pathname, mode).
4. What are the Unix system calls for I/O?
open(pathname,flag,mode) - open file
creat(pathname,mode) - create file
close(filedes) - close an open file
read(filedes,buffer,bytes) - read data from an open file
write(filedes,buffer,bytes) - write data to an open file
lseek(filedes,offset,from) - position an open file
dup(filedes) - duplicate an existing file descriptor
dup2(oldfd,newfd) - duplicate to a desired file descriptor
fcntl(filedes,cmd,arg) - change properties of an open file
ioctl(filedes,request,arg) - change the behaviour of an open file
The difference between fcntl anf ioctl is that the former is intended for any open file, while the latter is for device-specific operations.
5. How do you change File Access Permissions?
Every file has following attributes:
owner's user ID ( 16 bit integer )
owner's group ID ( 16 bit integer )
File access mode word
'r w x -r w x- r w x'
(user permission-group permission-others permission)
r-read, w-write, x-execute
To change the access mode, we use chmod(filename,mode).
Example 1:
To change mode of myfile to 'rw-rw-r–' (ie. read, write permission for user - read,write permission for group - only read permission for others) we give the args as:
chmod(myfile,0664) .
Each operation is represented by discrete values
'r' is 4
'w' is 2
'x' is 1
Therefore, for 'rw' the value is 6(4+2).
Example 2:
To change mode of myfile to 'rwxr–r–' we give the args as:
chmod(myfile,0744).
6. What is a FIFO?
FIFO are otherwise called as 'named pipes'. FIFO (first-in-first-out) is a special file which is said to be data transient. Once data is read from named pipe, it cannot be read again. Also, data can be read only in the order written. It is used in interprocess communication where a process writes to one end of the pipe (producer) and the other reads from the other end (consumer).
7. How do you create special files like named pipes and device files?
The system call mknod creates special files in the following sequence.
1. kernel assigns new inode,
2. sets the file type to indicate that the file is a pipe, directory or special file,
3. If it is a device file, it makes the other entries like major, minor device numbers.
For example:
If the device is a disk, major device number refers to the disk controller and minor device number is the disk.
8. Discuss the mount and unmount system calls
The privileged mount system call is used to attach a file system to a directory of another file system; the unmount system call detaches a file system. When you mount another file system on to your directory, you are essentially splicing one directory tree onto a branch in another directory tree. The first argument to mount call is the mount point, that is , a directory in the current file naming system. The second argument is the file system to mount to that point. When you insert a cdrom to your unix system's drive, the file system in the cdrom automatically mounts to /dev/cdrom in your system.
9. How does the inode map to data block of a file?
Inode has 13 block addresses. The first 10 are direct block addresses of the first 10 data blocks in the file. The 11th address points to a one-level index block. The 12th address points to a two-level (double in-direction) index block. The 13th address points to a three-level(triple in-direction)index block. This provides a very large maximum file size with efficient access to large files, but also small files are accessed directly in one disk read.
10. What is a shell?
A shell is an interactive user interface to an operating system services that allows an user to enter commands as character strings or through a graphical user interface. The shell converts them to system calls to the OS or forks off a process to execute the command. System call results and other information from the OS are presented to the user through an interactive interface. Commonly used shells are sh,csh,ks etc.
11. Brief about the initial process sequence while the system boots up.
While booting, special process called the 'swapper' or 'scheduler' is created with Process-ID 0. The swapper manages memory allocation for processes and influences CPU allocation. The swapper inturn creates 3 children:
the process dispatcher,
vhand and
dbflush
with IDs 1,2 and 3 respectively.
This is done by executing the file /etc/init. Process dispatcher gives birth to the shell. Unix keeps track of all the processes in an internal data structure called the Process Table (listing command is ps -el).
12. What are various IDs associated with a process?
Unix identifies each process with a unique integer called ProcessID. The process that executes the request for creation of a process is called the 'parent process' whose PID is 'Parent Process ID'. Every process is associated with a particular user called the 'owner' who has privileges over the process. The identification for the user is 'UserID'. Owner is the user who executes the process. Process also has 'Effective User ID' which determines the access privileges for accessing resources like files.
getpid() -process id
getppid() -parent process id
getuid() -user id
geteuid() -effective user id
13. Explain fork() system call.
The `fork()' used to create a new process from an existing process. The new process is called the child process, and the existing process is called the parent. We can tell which is which by checking the return value from `fork()'. The parent gets the child's pid returned to him, but the child gets 0 returned to him.
14. Predict the output of the following program code
main()
{
fork();
printf("Hello World!");
}
Answer:
Hello World!Hello World!
Explanation: The fork creates a child that is a duplicate of the parent process. The child begins from the fork().All the statements after the call to fork() will be executed twice.(once by the parent process and other by child). The statement before fork() is executed only by the parent process.
15. Predict the output of the following program code
Answer:
"Hello World" will be printed 8 times.
Explanation: 2^n times where n is the number of calls to fork()
16 . List the system calls used for process management:
System calls Description
fork() To create a new process
exec() To execute a new program in a process
wait() To wait until a created process completes its execution
exit() To exit from a process execution
getpid() To get a process identifier of the current process
getppid() To get parent process identifier
nice() To bias the existing priority of a process
brk() To increase/decrease the data segment size of a process.
17. How can you get/set an environment variable from a program?
Getting the value of an environment variable is done by using `getenv()'. Setting the value of an environment variable is done by using `putenv()'.
18. How can a parent and child process communicate?
A parent and child can communicate through any of the normal inter-process communication schemes (pipes, sockets, message queues, shared memory), but also have some special ways to communicate that take advantage of their relationship as a parent and child. One of the most obvious is that the parent can get the exit status of the child.
19. What is a zombie?
When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the child's exit status. To be able to get this information, the parent calls `wait()'; In the interval between the child terminating and the parent calling `wait()', the child is said to be a `zombie' (If you do `ps', the child will have a `Z' in its status field to indicate this.)
20. What are the process states in Unix?
As a process executes it changes state according to its circumstances. Unix processes have the following states:
Running : The process is either running or it is ready to run .
Waiting : The process is waiting for an event or for a resource.
Stopped : The process has been stopped, usually by receiving a signal.
Zombie : The process is dead but have not been removed from the process table.