Vous êtes sur la page 1sur 12

1. Explain the working of Virtual Memory. Virtual memory like as a temparary storage area.It consists of page table.

In this pages are divided into frames.It is a contingous memroy allocation.It is also called logical memory. Virtual memory is memory that appears to be allocated to application programs. The operating system uses a portion of the hard disk as virtual memory, and swaps data between the hard disk and physical memory. Virtual memory enables multitasking. If your computer needs to run several programs simultaneously, and the memory that all these programs require exceeds the amount of physical memory available, the operating system allocates virtual memory to meet the total memory requirements of each program, and then manages the available physical memory to meet the actual memory requirements at each point in time. Therefore, the amount of virtual memory that is allocated can be much greater than the amount of physical memory that is installed in the computer." --Physical memory and virtual memory TechNote. Utilizing virtual memory involves paging and swapping. Paging occurs when an active process requires more memory than what is accessible in physical memory. Portions of the process are moved to disk so the physical memory can be used for something else. Swapping is done by the kernel. When memory space is running low the kernel looks for a process that isn't likely to run in the near future. That process is written entirely to disk, and the newly-freed memory is reassigned to another process or job. 2. What is this line in the shell script do ??? #!/bin/ksh This line is called as "Hash Bang" Statement. This tells the OS that the particular needs the respective shell for execution. If a script file has this hash bang statement along with execution permission, then this file can be run directly without invoking thru shell command.Ex:$ instead of$ksh 3. How would you using the commands ps, cut, tr and kill, along with pipes, write a command that will find all sleep processes running on the system and kill them? ps -eaf|cut -d f2|tr -s " "|kill ps -eaf | tr -s ' ' | cut -d' ' -f2 | kill kill -9 'ps -eaf | tr -s ' ' | cut -d' ' -f2' 4. How does Windows NT supports Multitasking? Preemptive multitask 5. When you login to a c shell, which script would be run first? (before the terminal is ready for the user) For C shell , first /etc/.login script is run & after that ~/.login is run & then ~/.cshrc is run. or C shell , first /etc/.login script is run & after that ~/.login is run & then ~/.cshrc is run. When you login to a bash shell as a user, the /etc/profile and /etc/bashrc would be run. Also, the .bashrc and .profile files from /etc/skel directory will be copied to the user's home directory. 6. How Connect to a Database in Shell Programming?Please tell me Step by Step Suppose you are using db2 and ksh

---------------------------#!/usr/bin/ksh connect to <Serve Name>:<Port NO>@<Instance Name> user <USERID> using <Passwd> ----------------------------------If u have profile and catalog then ---------------------------------#!/usr/bin/ksh db2 connect to <SID> ----------------------------------To run a sample proc .. use the below db2 "<Proc Name>" To connect informix DB isql <DB instance@DB> To connect orancle DB sqlplus <DBinstance@DB> 7. What?s the conditional statement in shell scripting? if {condition} then ? fi 8. What is the difference between writing code in shell and editor Code in the script (Shell is interprted) as shell is a interpreter where as editor is not inter preter certain set of commands(predefined) are used to handle editor 9. How do you list currently running process? Ps ps -ef will list all the Processes running in the System. ps will list only the processes initiated by the current user. ps -eaf | grep RU -- will list out the Processes currently running in the System 10. How do you find out what?s your shell? echo $SHELL I would prefer "echo $0". This can be used to find what is your current working shell as well. echo $SHELL Just do an echo for the variable RANDON > echo $RANDOM , will return

- a 5-digit number if it's a Korne shell - just return the prompt , if it's a Borne shell - will return an undefined variable , if it's a C-shell 11. How would you print just the 25th line in a file (smallest possible script please)? sed -n '25p' filename.txt sed -n '10p' <filename> cat -n file|grep "25" sed -n '25p' filename.txt > output_fielname head -25 <filename>|tail -1 12. How do you stop all the processes, except the shell window? kill 0 13. If you have a string "one two three", which shell command would you use to extract the strings echo $string | cut -d" " -f1 echo $string | cut -d" " -f2 echo $string | cut -d" " -f3 set -- $string echo $1 echo $2 echo $3 echo $string| awk '{print $1}' echo $string| awk '{print $2}' echo $string| awk '{print $3}' 14. How do you write a while loop in shell? while {condition} do {statement} done 15. State the advantages of Shell scripting? There are many advantages of shell scripting some of them are, one can develop their own operating system with relevant features best suited to their organization than to rely on costly operating systems. Software applications can be designed according to their platform. 16. What are the different variables present in Linux shell? Variables can be defined by the programmer or developer they specify the location of a particular variable in the memory. There are two types of shells they are System variables and user defined variables. System variables are defined by the system and user defined variables are to be defined by the user (small letters). 17. How do you test for file properties in shell scripts? - -s filename tells you if the file is not empty, -f filename tells you whether the argument is a file, and not a directory, -d filename tests if the argument is a directory, and not a file, -w filename tests for writeability, -r filename tests for readability, -x filename tests for executability 18. How do u open a read only file in Unix? vi filename e.g vi abc.txt but you cannot write to it easy way if file is small cat filename and contents is display on screen More filename

this can be used even for large files.It will show the first page in the screen.By hitting the Spacebar, the next page can be viewed. 20. How would you get the character positions 10-20 from a text file? 1>cat filename.txt | cut -c 10-20 2>cat <filename> | cut -c10-20 21. What does $? return? Will return the status of the command which is executed lastly. 0 => Success 2 => Error $? ---> will give the exit status of last background process ZERO for sucess. NON-ZERO for unsuccess it checks the exit status of last executed command It also print the return value of a function. $? gives the Exit status of the last backgroud process running in the system. 0-->success 1-->error 2-->warning $? will have the return code or return status of the previous command. Ex: At the time of running the SQL queries, we can perform the Commit or Rollback based on the value of the Variable $?. Value=$? if [[ $Value == 0 ]] then db2 "commit" else db2 "rollback" fi 22. Explain about echo command? Echo command is used to display the value of a variable. There are many different options give different outputs such as usage c suppress a trailing line, returns a carriage line, -e enables interpretation, returns the carriage. 23. How do you write a for loop in shell? or {variable name} in {list} do {statement} done for i in `cat filename` do code done for i in `ls -1`

do code done while <condition> true do code done 24. How do you stop a process? kill pid 25. Explain about sourcing commands? Sourcing commands help you to execute the scripts within the scripts. For example sh command makes your program to run as a separate shell. .command makes your program to run within the shell. This is an important command for beginners and for special purposes. 26. What is use of "cut" command ??? give some examples. can we use "awk" or "sed" instead of "cut" ??? if yes then give some examples This utility is use to cut out columns from a table or fields from each line of a file. cut can be used as a filter. Either the -b, -c, or -f option must be specified. -b list The list following -b specifies byte positions (for instance, -b1-72 would pass the first 72 bytes of each line). When -b and -n are used together, list is adjusted so that no multi-byte character is split. -c list The list following -c specifies character positions (for instance, -c1-72 would pass the first 72 characters of each line). -d delim The character following -d is the field delimiter (-f option only). Default is tab. Space or other characters with special meaning to the shell must be quoted. delim can be a multi-byte character. "cut" it self giving the meaning. It will cut words,charecters also by length. see "man cut " you will get more information who -Hu | awk '{print $8}' 27. What is the difference between a 'thread' and a 'process'? A process is a collection of virtual memory space, code, data, and system resources. A thread is code that is to be serially executed within a process. A processor executes threads, not processes, so each application has at least one process, and a process always has at least one thread of execution, known as the primary thread. A process can have multiple threads in addition to the primary thread Thread ? is stream of executable code within process. They are light weight process. All thread with in a process share process instruction,code & data segment,open file

descriptor,signal handler,userID and GroupID. Thread has its own set of register including program counter,stack pointer The major difference between threads and processes is 1.Threads share the address space of the process that created it; processes have their own address. 2.Threads have direct access to the data segment of its process; processes have their own copy of the data segment of the parent process. 3.Threads can directly communicate with other threads of its process; processes must use interprocess communication to communicate with sibling processes. 4.Threads have almost no overhead; processes have considerable overhead. 5.New threads are easily created; new processes require duplication of the parent process. 6.Threads can exercise considerable control over threads of the same process; processes can only exercise control over child processes. 7.Changes to the main thread (cancellation, priority change, etc.) may affect the behavior of the other threads of the process; changes to the parent process does not affect child processes. 28. Explain about the slow execution speed of shells? Major disadvantage of using shell scripting is slow execution of the scripts. This is because for every command a new process needs to be started. This slow down can be resolved by using pipeline and filter commands. A complex script takes much longer time than a normal script. 29. How do you send a mail message to somebody? mail somebody@something.com -s ?Your subject? -c ?cc@something.com? 30. How do you count words, lines and characters in a file? wc 31. How do you search for a string in a directory with the subdirectories recursed? grep -r string * 32. What is MUTEX? 1. Mutexes can synchronize threads within the same process or in other processes. 2. Mutexes can be used to synchronize threads between processes if the mutexes are allocated in writable memory and shared among the cooperating processes and have been initialized for this task. 33. How do you fire a process in the background? ./process-name & 34. What is shell scripting? Shell scripting is used to program command line of an operating system. Shell Scripting is also used to program the shell which is the base for any operating system. Shell scripts often refer to programming UNIX. Shell scripting is mostly used to program operating systems of windows, UNIX, Apple, etc. Also this script is used by companies to develop their own operating system with their own features.

35. How do you search for a string inside a given file? grep string filename 36. How do you find out your own username? whoami who am i who am i will give the exact username which we logged in. for example , If we use su command, it will runs a subshell with the effective user ID and privileges of the root user. In this case, if we use whoami, it will display the username as root. We can get the exact username by using the command who am i. "id" can be used to see the user currently logged in. whoami This is just give the username, where as "who am i" will give additional details like terminal info, ip, etc.. 37. How do you search for a string inside a directory? grep string * 38. Give some situations where typing error can destroy a program? There are many situations where typing errors can prove to be a real costly effort. For example a single extra space can convert the functionality of the program from deleting the sub directories to files deletion. cp, cn, cd all resemble the same but their actual functioning is different. Misdirected > can delete your data. 39. Different types of shells The Bourne shell (sh) , The C shell (csh) , The Korn shell (ksh) , The Z-Shell (zsh) , The POSIX shell, The Bourne Again SHell (Bash)null Tenex C shell is advanced form of C shell #cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/tcsh /bin/csh /bin/ksh /bin/zsh 40. What are PIDs? They are process IDs given to processes. A PID can vary from 0 to 65535.

41. How do you do number comparison in shell scripts? - -eq, -ne, -lt, -le, -gt, -ge 42. How do you refer to the arguments passed to a shell script? $1, $2 and so on. $0 is your script name. 43. How do you find out the number of arguments passed to the shell script? $# 44. How do you read keyboard input in shell scripts? read {variable-name} 45. Explain about Stdin, Stdout and Stderr? These are known as standard input, output and error. These are categorized as 0, 1 and 2. Each of these functions has a particular role and should accordingly functions for efficient output. Any mismatch among these three could result in a major failure of the shell. 46. Explain about non-login shell files? The non login shell files are initialized at the start and they are made to run to set up variables. Parameters and path can be set etc are some important functions. These files can be changed and also your own environment can be set. These functions are present in the root. It runs the profile each time you start the process. 47. What?s the command to find out users on the system? who who | awk '{print $1}' 48. How do you remove a file? rm -rf Files can be removed with different options.They are as follows : 1) to remove a file : #rm <filename> 2) to remove a file with user interaction : #rm -i <filename> 3) to remove a file with confirmation : #rm -b <filename> 4) to remove a file forcefully even it has no write permissions : #rm -f <filename> Removing a directory : 1) rmdir <directory name> 2) rm -r <directory name> 3) m -rf <filename> (It will neglect all the special characters) 49. Explain about GUI scripting? Graphical user interface provided the much needed thrust for controlling a computer and its applications. This form of language simplified repetitive actions. Support for different applications mostly depends upon the operating system. These interact with menus, buttons, etc. 50. Explore about Environment variables? Environment variables are set at the login time and every shell that starts from this shell gets a copy of the variable. When we export the variable it changes from an shell variable to an environment variable and these variables are initiated at the start of the shell.

51. Write a shell script to identify the given string is palindrome or not? Print("Please enter a string "); $input_string = <STDIN>; chop($input_string); $rev_string = reverse($input_string); if($input_string eq $rev_string){ print("The string is a palindrome"); }else{ print("The string is NOT a palindrome"); } Check the script 1=0 cnt=1 tag=0 echo "Enter a String?" read str 1 =`echo $str |wc -c` 1 =`expr $l - 1` 1h=`expr $l / 2` while [ $cnt -le $lh ] do c1=`echo $str|cut -c$cnt` c2=`echo $str|cut -c$l` if [ $c1 != $c2 ] then cnt=$lh tag=1 fi cnt=`expr $cnt + 1` =`expr $l - 1` done if [ $tag -eq 0 ] then echo "String is Palindrome" else echo ?String is not Palindrome? fi 52. How do you find out about all running processes? ps -ag 53. How does a case statement look in shell scripts? case {variable} in {possible-value-1}) {statement};; {possible-value-2}) {statement};; esac 54. How do you send a mail message to somebody? mail 55. Explain about shebang? Shebang is nothing but a # sign followed by an exclamation. This is visible at the top of the script and it is immediately followed by an exclamation. To avoid repetitive work each time

developers use shebang. After assigning the shebang work we pass info to the interpreter. 56. What is the difference between a shell variable that is exported and the one that is not exported? export LANG=C will make the variable LANG the global variable, put it into the global environment. all other processes can use it. LANG=C will change the value only in the current script. 57. How do you read arguments in a shell program - $1, $2 ... Shell script accepts parameters in following format... $1 : first $2 : second....so on upto $9 : 9th param whereas $0 : gives script/function name If your script has more than 9 params then accept in following way... ${12} : 12th param ${18} : 18th param for x in $* do echo ${x} done will read one by one and print it 58. How do you find out the current directory you?re in? pwd 59. Explain about the Exit command? Every program whether on UNIX or Linux should end at a certain point of time and successful completion of a program is denoted by the output 0. If the program gives an output other than 0 it defines that there has been some problem with the execution or termination of the problem. Whenever you are calling other function, exit command gets displayed. 60. How do you schedule a command to run at 4:00 every morning? Step 1. Set environemen variable EDITOR=vi if not set Step 2. Give command crontab -e Step 3. Add following entry at the end 0 4 * * * <Your command to run at 4:00 am morning> 61. What?s a way to do multilevel if-else?s in shell scripting? if {condition} then {statement} elif {condition} {statement} fi 62. What?s the command to find out today?s date? date

63. How will you list only the empty lines in a file (using grep) grep "^[ ]*$" filename.txt In character set (between [ and ] one space and tab is given) this command will gives all the blank line including those having space and tabs (if pressed)only cat sample.txt | grep "^$" This will give you, all the blank line from the file sample.txt . If you want the output as: all the lines without blank lines use following command: cat sample.txt | grep -v "^$" 64. How do you remove a file? rm 65. What is INODE? The inode is the focus of all file activity in the file system. There is a unique inode allocated for each active file, each current directory, each mounted-on file, text file, and the root. An inode is "named" by its device/i-number pair. 66. How would you replace the n character in a file with some xyz? vi file name then go to command mode %s/n/xyz/g 67. How do you do Boolean logic operators in shell scripting? - ! tests for logical not, -a tests for logical and, and -o tests for logical or. 68. What are the disadvantages of shell scripting? There are many disadvantages of shell scripting they are * Design flaws can destroy the entire process and could prove a costly error. * Typing errors during the creation can delete the entire data as well as partition data. * Initially process is slow but can be improved. * Portbility between different operating system is a prime concern as it is very difficult to port scripts etc. 69. How does getopts command work? The parameters to your script can be passed as -n 15 -x 20. Inside the script, you can iterate through the getopts array as while getopts n:x option, and the variable $option contains the value of the entered option. 70. What is $* $1: the 1st parameter $2: the 2nd parameter ... $* All parameters in the command line 71. How do you define a function in a shell script? function-name() { #some code here return } 72. What is the difference between a shell variable that is exported and the one that is not exported? export LANG=C will make the variable LANG the global variable, put it into the global environment. all other

processes can use it. LANG=C will change the value only in the current script. 73. Explain about Login shell? Login shell is very useful as it creates an environment which is very useful to create the default parameters. It consists of two files they are profile files and shell rc files. These files initialize the login and non login files. Environment variables are created by Login shell. 74. How would you get the character positions 10-20 from a text file? cat filename.txt | cut -c 10-20 cat <filename> | cut -c10-20 sed -n '10,20p' <file_name> 75. What does $# stand for? $# means, number of positional parameters set 76. What are the different kinds of loops available in shell script Broadly categorised in 3 for while until

Vous aimerez peut-être aussi