|
|
UNIX INTERVIEW QUESTIONS
|
61. What Is A Shell
Date Posted: 07/02/2012
Ans: A shell is an interactive user interface to an operating system service 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.
|
|
|
62. How Does The Inode Map To Data Block Of A File
Date Posted: 07/02/2012
Ans: 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.
|
|
|
63. How To Get The CPU And Memory Details In Linux Server?
Date Posted: 07/02/2012
Ans: In Linux based systems, you can easily access the CPU and memory details from the /proc/cpuinfo and /proc/meminfo, like this:
$>cat /proc/meminfo
$>cat /proc/cpuinfo
Just try the above commands in your system to see how it works
|
|
|
64. How To Tell If My Process Is Running In Unix?
Date Posted: 07/02/2012
Ans: You can list down all the running processes using [ps] command. Then you can “grep” your user name or process name to see if the process is running. See below:
$>ps -e -o stime,user,pid,args,%mem,%cpu | grep "opera"
14:53 opera 29904 sleep 60 0.0 0.0
14:54 opera 31536 ps -e -o stime,user,pid,arg 0.0 0.0
14:54 opera 31538 grep opera 0.0 0.0
|
|
|
65.
Ans: The standard command to see this is [ps]. But [ps] only shows you the snapshot of the processes at that instance. If you need to monitor the processes for a certain period of time and need to refresh the results in each interval, consider using the [top] command.
$> ps –ef
If you wish to see the % of memory usage and CPU usage, then consider the below switches
$> ps aux
If you wish to use this command inside some shell script, or if you want to customize the output of [ps] command, you may use “-o” switch like below. By using “-o” switch, you can specify the columns that you want [ps] to print out.
$>ps -e -o stime, user, PID, args, %mem, %cpu
How To Check All The Running Processes In UNIX?
Date Posted: 07/02/2012
Ans: The standard command to see this is [ps]. But [ps] only shows you the snapshot of the processes at that instance. If you need to monitor the processes for a certain period of time and need to refresh the results in each interval, consider usi...
|
|
|
66. How To Check If A File Is Present In A Particular Directory In UNIX?
Date Posted: 07/02/2012
Ans: Using command, we can do it in many ways. Based on what we have learnt so far, we can make use of [ls] and [$?] command to do this. See below:
$> ls –l file.txt; echo $?
If the file exists, the [ls] command will be successful. Hence [echo $?] will print 0. If the file does not exist, then [ls] command will fail and hence [echo $?] will print 1.
|
|
|
67. How To Check If The Last Command Was Successful In UNIX?
Date Posted: 07/02/2012
Ans: To check the status of last executed command in UNIX, you can check the value of an inbuilt bash variable [$?]. See the below example:
$> echo $?
|
|
|
68. How To List Down File/folder Lists Alphabetically?
Date Posted: 07/02/2012
Ans: Normally [ls –lt] command lists down file/folder list sorted by modified time. If you want to list then alphabetically, then you should simply specify: [ls –l]
|
|
|
69. How To Fail A Shell Script Programmatically?
Date Posted: 07/02/2012
Ans: Just put an [exit] command in the shell script with return value other than 0. this is because the exit codes of successful Unix programs is zero. So, suppose if you write
Exit -1
Inside your program, then your program will thrown an error and exit immediately.
|
|
|
70. How To Check The Command Line Arguments In A UNIX Command In Shell Script?
Date Posted: 07/02/2012
Ans: In a bash shell, you can access the command line arguments using $0, $1, $2, variables, where $0 prints the command name, $1 prints the first input parameter of the command, $2 the second input parameter of the command and so on.
|
|
|
|
|