UNIX Labmanual
Transcript of UNIX Labmanual
-
8/9/2019 UNIX Labmanual
1/56
1
INDEX
S.No Contents Page No.
1 Lab Objective2
2 Introduction About Lab3
3 Guidelines to Students5
4 List of Syllabus Programs (JNTU)7
5 Description about UNIX commands 10
6 Discription about shells20
6 Solutions for Programs22
7 Viva Questions and Answers35
8 References
55
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
2/56
2
LAB OBJECTIVE
Upon successful completion of this Lab the student will be able to:
1. Demonstrate how to use the following Bourne Shell commands: cat, grep, ls,more, ps, chmod, finger, ftp, etc.
2. Use the following Bourne Shell constructs: test, if then, if then else, if then elif,for, while, until, and case.
3. Learn tracing mechanisms (for debugging), user variables, BourneShell variables,read-only variables, positional parameters, reading input to a BourneShell script,command substitution, comments, and exporting variables. In addition, test on numericvalues, test on file type, and test on character strings are covered.
4. Copy, move, and delete files and directories
5. Write moderately complex Shell scripts.
6. Make a Shell script executable.
7. Create a ".profile" script to customize the user environment.
8. Use advanced features of File Transfer Protocol (FTP)
9. Compile source code into object and executable modules.
10. Execute programs written in c under UNIX environment
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
3/56
3
INTRODUCTION ABOUT LAB
There are 66 systems ( Compaq Presario ) installed in this Lab.Their configurations are as follows :
Processor : AMD Athelon 1.67 GH z
RAM : 256 MB
Hard Disk : 40 GB
Mouse : Optical Mouse
Network Interface card : Present
Software
All systems are configured in DUAL BOOT mode i.e, Students can bootfrom Windows XP or Linux as per their lab requirement.
This is very useful for students because they are familiar with differentOperating Systems so that they can execute their programs in different
programming environments.
Each student has a separate login for database access
Oracle 9i client version is installed in all systems. On the server, account for eachstudent has been created.
This is very useful because students can save their work ( scenarios, pl/sql programs, data related projects ,etc) in their own accounts. Each studentwork is safe and secure from other students.
Latest Technologies like DOT NET and J2EE are installed in some systems.Before submitting their final project, they can start doing mini project from 2 nd
year onwards.
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
4/56
4
MASM ( Macro Assembler ) is installed in all the systems
Students can execute their assembly language programs using MASM.MASM is very useful students because when they execute their programsthey can see contents of Processor Registers and how each instruction is
being executed in the CPU.
Rational Rose Software is installed in some systems
Using this software, students can depict UML diagrams of their projects.
Softwares installed : C, C++, JDK1.5, MASM, OFFICE-XP, J2EE and DOT NET, Rational Rose.
Systems are provided for students in the 1:1 ratio.
Systems are assigned numbers and same system is allotted for studentswhen they do the lab.
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
5/56
5
Guidelines to Students
How to Run Shell Scripts
There are two ways you can execute your shell scripts. Once you have created a scriptfile:
Method 1Pass the file as an argument to the shell that you want to interpret your script.
Step 1 : create the script using vi, ex or ed
For example, the script file show has the following lines
echo Here is the date and timedate
Step 2 : To run the script, pass the filename as an argument to the sh (shell )
$ sh showHere is the date and timeSat jun 03 13:40:15 PST 2006
Method 2:Make your script executable using the chmod command.
When we create a file, by default it is created with read and write permission turned onand execute permission turned off. A file can be made executable using chmod.
Step 1 : create the script using vi, ex or ed
For example, the script file show has the following lines
echo Here is the date and timedate
Step 2 : Make the file executable
$ chmod u+x script_file$ chmod u+x show
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
6/56
6
Step 3 : To run the script, just type the filename
$ showHere is the date and time
Sat jun 03 13:40:15 PST 2006
How to run C programs
Step 1 : Use an editor, such as vi, ex, or ed to write the program. The name of the filecontaining the program should end in .c.
For example, the file show.c contains the following lines :
main(){
printf( welcome to GNEC );}
Step 2 : Submit the file to CC ( the C Compiler )
$ cc show.c
If the program is okay, the compiled version is placed in a file called a.out
Step 3 : To run the program, type a.out
$ a.out
Welcome to GNEC
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
7/56
7
List of Lab Exercises
Syllabus Programs ( JNTU )
WEEK1Session 1
1. Log in to the system2. Use Vi editor to create a file called myfile.txt which contain some text.3. Correct typing errors during creation4. Save the file5. Logout of the file
Session 2
a) Log into the system b) Open the file created in session 1c) Add some textd) Change some texte) delete some textf) Save the changesg) Logout of the system
WEEK2
a) log into the system b) Use the cat command to create a file containing the following data. Call it
mutable use tabs to separate the fields1425 ravi 15.654320 ramu 26.276830 sita 36.151450 raju 21.86
c) use the cat command to display the file, my tabled) use the vi command to correct any errors in the file, my tablee) use the sort command to sort the file my table according to the first field. Call the
sorted file my table(same name)f) print the file my tableg) use the cut & paste commands to swap fields 2 and 3 my table. Call it
mytable(same name)h) print the new file, my tablei) logout of the system
WEEK3
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
8/56
8
a) log in the system b) use the appropriate commands to determine ur login shellc) use the /etc/passwd file to verify the result of step b.d) use the who command redirect the result to a file called myfile1.Use the more
command to see the contents of myfile1.
e) Use the date and who commands in sequence ?(in one line) such that the output of date will display on the screen and the output of who will be redirected to a filecalled my file2.Use the more command to check the contents of myfile2.
a) write a sed command that deletes the first character in each line in a file b) write a sed command that deletes the character before the last character in each
line in a file.c) Write a sed command that swaps the files and second words in each line in a file
WEEK4
a) pipe ur /etc/passwd file to awk and print out the home directory of each user.
b) Develop an interactive grep script that asks for a word and a file name and thentells how many lines contain that wordc) Repeatd) Part using awk
WEEK5
a) Write A shell script that takes a command line argument and reports on whether it isdirectry ,a file,or something else
b) Write a shell script that accepts one or more file name as a arguments and converts allof thenm to uppercase,provided they exits in the current directory
c) Write a shell script that determines the period for which a specified user is working onthe system
WEEK6
a) write a shell script that accepts a file name starting and ending line numbers asarguments and displays all the lines between the given line numbers
b) write a shell script that deletes all lines containing a specified word I one or morefiles supplied as arguments to it.
WEEK7
a) Write a shell script that computes the gross salary of a employee according to thefollowing
1) if basic salary is 1500 then HRA 500 and DA =98% of the basicThe basic salary is entered interactively through the key board
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
9/56
9
b) Write a shell script that accepts two integers as its arguments and computes thevalue of first number raised to the power of the second number
WEEK 8
a) Write an interactive file handling shell program. Let it offer the user the choice of copying ,removing ,renaming or linking files. Once the use has made a choice,have the program ask the user for necessary information, such as the file name,new name and so on.
b) Write a shell script that takes a login name as command line argument andreports when that person logs in
c) Write a shell script which receives two files names as arguments. It should check whether the two file contents are same or not. If they are same then second fileshould be deleted.
WEEK 9
a) Write a shell script that displays a list of all files in the current directory to whichthe user has read write and execute permissions
b) Develop an interactive script that asks for a word and file name and then tells howmany times that word occurred in the file.
c) Write a shell script to perform the following string operations.
1) To extract a sub string from a given string2) To find the length of a given string
WEEK 10
Write a C program that takes one or more file or directory names as command line inputand reports the following information on the file.
1) file type2) number of links3) read, write and execute permissions4) time of last access
(Note: use /fstat system calls)
WEEK 11
Write C program that simulate the following unix commandsa) mv
b) cp
WEEK 12
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
10/56
10
Write a c program that simulates ls command(Use system calls /directory API)
Basic Unix commands
Command CATSyntax cat [argument] [specific file]
Description cat" is short for concatenate. This command is used tocreate, view and concatenate files.
Examples cat /etc/passwd
This command displays the "/etc/passwd" file on your screen.
cat /etc/profile
This command displays the "/etc/profile" file on your screen. Notice that some of the contents of this file may scroll off of your screen.
cat file1 file2 file3 > file4
This command combines the contents of the first three filesinto the fourth file.
Command pwd
Syntax pwd
Description "pwd" stands for print working directory. It displaysyour current position in the UNIX filesystem.
Examples pwd
There are no options (or arguments) with the "pwd"command. It is simply used to report your current workingdirectory.
Command lsSyntax ls [options] [names]
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
11/56
11
Description "ls" stands for list. It is used to list information aboutfiles and directories.Examples ls
This is the basic "ls" command, with no options. It provides avery basic listing of the files in your current workingdirectory. Filenames beginning with a decimal are consideredhidden files, and they are not shown.
ls -a
The -a option tells the ls command to report information aboutall files, including hidden files.
ls -l
The -l option tells the "ls" command to provide a long listingof information about the files and directories it reports. Thelong listing will provide important information about file
permissions, user and group ownership, file size, and creationdate.
ls -al
This command provides a long listing of information about all files in the current directory. It combines the functionality of the -a and -l options. This is probably the most used version of the ls command .
ls -al /usr
This command lists long information about all files in the"/usr" directory.
ls -alR /usr | more
This command lists long information about all files in the"/usr" directory, and all sub-directories of /usr. The -R optiontells the ls command to provide a recursive listing of all filesand sub-directories.
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
12/56
12
ls -ld /usr
Rather than list the files contained in the /usr directory, thiscommand lists information about the /usr directory itself
(without generating a listing of the contents of /usr). This isvery useful when you want to check the permissions of thedirectory, and not the files the directory contains.
Command mvSyntax mv [options] sources target
Options -b backup files that are about to be overwritten or removed-i interactive mode; if dest exists, you'll be asked whether tooverwrite the file
Description The "mv" command is used to move and rename files.Examples mv Chapter1 Chapter1.bad
This command renames the file "Chapter1" to the new name"Chapter1.bad".
mv Chapter1 garbage
This command renames the file "Chapter1" to the new name"garbage". (Notice that if "garbage" is a directory, "Chapter1"would be moved into that directory).
mv Chapter1 /tmp
This command moves the file "Chapter1" into the directorynamed "/tmp".
mv tmp tmp.old
Assuming in this case that tmp is a directory, this examplerenames the directory tmp to the new name tmp.old.
Command rmSyntax rm [options] files
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
13/56
13
Options -d, --directoryunlink FILE, even if it is a non-empty directory
(super-user only)
-f, --force
ignore nonexistent files, never prompt
-i, --interactiveprompt before any removal
-r, -R, --recursiveremove the contents of directories recursively
-v, --verboseexplain what is being done
Description The "rm" command is used to remove files anddirectories. (Warning - be very careful when removingfiles and directories!)
Examples rm Chapter1.bad
This command deletes the file named "Chapter1.bad"(assuming you have permission to delete this file).
rm Chapter1 Chapter2 Chapter3
This command deletes the files named "Chapter1","Chapter2", and "Chapter3".
rm -i Chapter1 Chapter2 Chapter3
This command prompts you before deleting any of the threefiles specified. The -i option stands for inquire . You mustanswer y (for yes) for each file you really want to delete. Thiscan be a safer way to delete files.
rm *.html
This command deletes all files in the current directory whosefilename ends with the characters ".html".
rm index*
This command deletes all files in the current directory whose
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
14/56
14
filename begins with the characters "index".
rm -r new-novel
This command deletes the directory named "new-novel". Thisdirectory, and all of its' contents, are erased from the disk,including any sub-directories and files.
Command cpSyntax cp [options] file1 file2
cp [options] files directory
Options -b backup files that are about to be overwritten or removed-i interactive mode; if dest exists, you'll be asked whether to
overwrite the file-p preserves the original file's ownership, group,
permissions, and timestamp
Description The "cp" command is used to copy files and directories.
Note that when using the cp command, you must alwaysspecify both the source and destination of the file(s) to becopied.
Examples cp .profile .profile.bak
This command copies your ".profile" to a file named".profile.bak".
cp /usr/fred/Chapter1 .
This command copies the file named "Chapter1" in the"/usr/fred" directory to the current directory. This exampleassumes that you have write permission in the currentdirectory.
cp /usr/fred/Chapter1 /usr/mary
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
15/56
15
This command copies the "Chapter1" file in "/usr/fred" to thedirectory named "/usr/mary". This example assumes that youhave write permission in the "/usr/mary" directory.
Command grepSyntax grep [options] regular expression [files]
Options -i case-insensitive search-n show the line# along with the matched line-v invert match, e.g. find all lines that do NOT
match
-w match entire words, rather than substrings
Description Think of the "grep" command as a "search" command(most people wish it was named "search"). It is used tosearch for text strings within one or more files.
Examples grep 'fred' /etc/passwd
This command searches for all occurrences of the text string'fred' within the "/etc/passwd" file. It will find and print (onthe screen) all of the lines in this file that contain the text
string 'fred', including lines that contain usernames like "fred"- and also "alfred".
grep '^fred' /etc/passwd
This command searches for all occurrences of the text string'fred' within the "/etc/passwd" file, but also requires that the"f" in the name "fred" be in the first column of each record(that's what the caret character tells grep). Using this more-advanced search, a user named "alfred" would not bematched, because the letter "a" will be in the first column.
grep 'joe' *
This command searches for all occurrences of the text string'joe' within all files of the current directory.
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
16/56
16
Command mkdir Syntax mkdir [options] directory name
Description The "mkdir" command is used to create new directories(sub-directories).
Examples mkdir tmp
This command creates a new directory named "tmp" in your current directory. (This example assumes that you have the
proper permissions to create a new sub-directory in your current working directory.)
mkdir memos letters e-mail
This command creates three new sub-directories (memos,letters, and e-mail) in the current directory.
mkdir /usr/fred/tmp
This command creates a new directory named "tmp" in thedirectory "/usr/fred". "tmp" is now a sub-directory of "/usr/fred". (This example assumes that you have the proper
permissions to create a new directory in /usr/fred.)
mkdir -p /home/joe/customer/acme
This command creates a new directory named/home/joe/customer/acme, and creates any intermediatedirectories that are needed. If only /home/joe existed to beginwith, then the directory "customer" is created, and thedirectory "acme" is created inside of customer.
Command rmdir Syntax rmdir [options] directoriesDescription The "rm" command is used to remove files and
directories. (Warning - be very careful when removingfiles and directories!)
Examples rm Chapter1.bad
This command deletes the file named "Chapter1.bad"
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
17/56
17
(assuming you have permission to delete this file).
rm Chapter1 Chapter2 Chapter3
This command deletes the files named "Chapter1","Chapter2", and "Chapter3".
rm -i Chapter1 Chapter2 Chapter3
This command prompts you before deleting any of the threefiles specified. The -i option stands for inquire . You mustanswer y (for yes) for each file you really want to delete. Thiscan be a safer way to delete files.
rm *.html
This command deletes all files in the current directory whosefilename ends with the characters ".html".
rm index*
This command deletes all files in the current directory whosefilename begins with the characters "index".
rm -r new-novel
This command deletes the directory named "new-novel". Thisdirectory, and all of its' contents, are erased from the disk,including any sub-directories and files.
Command cd, chdir Syntax cd [name of directory you want to move to]
Description "cd" stands for change directory. It is the primarycommand for moving around the filesystem.
Examples cd /usr
This command moves you to the "/usr" directory. "/usr"
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
18/56
18
becomes your current working directory.
cd /usr/fred
Moves you to the "/usr/fred" directory.
cd /u*/f*
Moves you to the "/usr/fred" directory - if this is the onlydirectory matching this wildcard pattern.
cd
Issuing the "cd" command without any arguments moves youto your home directory.
cd -
Using the Korn shell, this command moves you back to your previous working directory. This is very useful when you're inthe middle of a project, and keep moving back-and-forth
between two directories.
Command killSyntax kill [options] IDs
Description kill ends one or more process IDs. In order to do this youmust own the process or be designated a privileged user. Tofind the process ID of a certain job use ps.
Examples
Command psSyntax ps [options]
Description The "ps" command (process statistics) lets you check the status of processes that are running on your Unixsystem.
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://webmonkey.com/webmonkey/reference/unix_guide/ps.htmlhttp://webmonkey.com/webmonkey/reference/unix_guide/ps.html -
8/9/2019 UNIX Labmanual
19/56
19
Examples ps
The ps command by itself shows minimal information aboutthe processes you are running. Without any arguments, thiscommand will not show information about other processes
running on the system.
ps -f
The -f argument tells ps to supply full information about the processes it displays. In this example, ps displays fullinformation about the processes you are running.
ps -e
The -e argument tells the ps command to show every processrunning on the system.
ps -ef
The -e and -f arguments are normally combined like this toshow full information about every process running on thesystem. This is probably the most often-used form of the pscommand.
ps -ef | more
Because the output normally scrolls off the screen, the outputof the ps -ef command is often piped into the more command.The more command lets you view one screenful of information at a time.
ps -fu fred
This command shows full information about the processescurrently being run by the user named fred (the -u option letsyou specify a username).
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
20/56
20
Why Use Shells?
Well, most likely because the are a simple way to string together a bunch of UNIXcommands for execution at any time without the need for prior compilation. Also becauseits generally fast to get a script going. Not forgetting the ease with which other scripters
can read the code and understand what is happening. Lastly, they are generallycompletely portable across the whole UNIX world, as long as they have been written to acommon standard.
The Shell History:
The basic shells come in three main language forms. These are (in order of creation) sh,csh and ksh . Be aware that there are several dialects of these script languages which tendto make them all slightly platform specific. Where these differences are known to causedifficulties I have made special notes within the text to highlight this fact. The differentdialects are due, in the main, to the different UNIX flavours in use on some platforms.
All script languages though have at their heart a common core which if used correctlywill guarantee portability.
Bourne Shell:
Historically the sh language was the first to be created and goes under the name of TheBourne Shell. It has a very compact syntax which makes it obtuse for novice users butvery efficient when used by experts. It also contains some powerful constructs built in.On UNIX systems, most of the scripts used to start and configure the operating systemare written in the Bourne shell. It has been around for so long that is it virtually bug free.I have adopted the Bourne shell syntax as the defacto standard within this book.
C Shell:
Next up was The C Shell ( csh ), so called because of the similar syntactical structures tothe C language. The UNIX man pages contain almost twice as much information for theC Shell as the pages for the Bourne shell, leading most users to believe that it is twice asgood. This is a shame because there are several compromises within the C Shell whichmakes using the language for serious work difficult (check the list of bugs at the end of
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://www.injunea.demon.co.uk/pages/page203.htm#top%23tophttp://www.injunea.demon.co.uk/pages/page203.htm#top%23tophttp://www.injunea.demon.co.uk/pages/page203.htm#top%23tophttp://www.injunea.demon.co.uk/pages/page203.htm#top%23tophttp://www.injunea.demon.co.uk/pages/page203.htm#top%23tophttp://www.injunea.demon.co.uk/pages/page203.htm#top%23top -
8/9/2019 UNIX Labmanual
21/56
21
the man pages!). True, there are so many functions available within the C Shell that if oneshould fail another could be found. The point is do you really want to spend your timefinding all the alternative ways of doing the same thing just to keep yourself out of trouble. The real reason why the C Shell is so popular is that it is usually selected as thedefault login shell for most users. The features that guarantee its continued use in this
arena are aliases, and history lists. There are rumours however, that C Shell is destined to be phased out, with future UNIX releases only supporting sh and ksh . Differences between csh and sh syntax will be highlighted where appropriate.
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
22/56
22
Korne Shell:
Lastly we come to The Korne Shell ( ksh ) made famous by IBM's AIX flavour of UNIX.The Korne shell can be thought of as a superset of the Bourne shell as it contains thewhole of the Bourne shell world within its own syntax rules. The extensions over andabove the Bourne shell exceed even the level of functionality available within the C Shell(but without any of the compromises!), making it the obvious language of choice for realscripters. However, because not all platforms are yet supporting the Korne shell it is not
fully portable as a scripting language at the time of writing. This may change however bythe time this book is published. Korne Shell does contain aliases and history lists aplenty
but C Shell users are often put off by its dissimilar syntax. Persevere, it will pay off eventually. Any sh syntax element will work in the ksh without change.
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://www.injunea.demon.co.uk/pages/page203.htm#top%23tophttp://www.injunea.demon.co.uk/pages/page203.htm#top%23top -
8/9/2019 UNIX Labmanual
23/56
23
SOLUTIONS:
WEEK1Session 1
1. Log in to the system2. Use Vi editor to create a file called myfile.txt which containsome text.
3. Correct typing errors during creation4. Save the file5. Logout of the file
Sol:
$ login: $ password: ******
$ vi~ Unix is Case Sensitive~ Never leave the Computer without logging out when you are working in atime sharing or network environments.
Type : wq myfile
$Session 2
1. Log into the system2. Open the file created in session 13. Add some text4. Change some text5. delete some text6. Save the changes7. Logout of the system
Sol:$ login: $ password: ******
$ vi myfile
~ Unix is Case Sensitive~ Never leave the Computer without logging out when you are working in atime sharing or network environments.~ Shell Programming
: wq
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
24/56
24
WEEK2Log into the systemUse the cat command to create a file containing the following data. Call itmutable use tabs to separate the fields
1425 ravi 15.654320 ramu 26.276830 sita 36.151450 raju 21.86
a. use the cat command to display the file, my tableb. use the vi command to correct any errors in the file, my tablec. use the sort command to sort the file my table according to the
first field. Call the sorted file my table(same name)d. print the file my tablee. use the cut & paste commands to swap fields 2 and 3 my table.
Call it mytable(same name)f. print the new file, my tableg. logout of the system
Sol:
$ login: $ password:******
$ cat c1-14
1425 ravi 15.65 4320 ramu 26.27 6830 sita 36.15 1450 raju 21.86
$ cat myfile$who|more$ sort +0 -1 mytable
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
25/56
25
WEEK3
a. log in the system
b. use the appropriate commands to determine ur login shellc. use the /etc/passwd file to verify the result of step b.d. use the who command redirect the result to a file called
myfile1.Use the more command to see the contents of myfile1.e. Use the date and who commands in sequence ?(in one line) such
that the output of date will display on the screen and the output of who will be redirected to a file called my file2.Use the morecommand to check the contents of myfile2.
f. write a sed command that deletes the first character in each line ina file
g. write a sed command that deletes the character before the last
character in each line in a file.h. Write a sed command that swaps the files and second words ineach line in a file
Sol:
$ login: $ password:******
$ echo $SHELLcsh
$ who >| myfile1$ more myfile1
$ date|who >myfile2$ more myfile2
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
26/56
26
WEEK4
pipe ur /etc/passwd file to awk and print out the home directory of each user.Develop an interactive grep script that asks for a word and a file name and thentells how many lines contain that word
RepeatPart using awk
(d) Sol:$ awk $2 ==Computers && $3 >10000 {print}Sales.dat
I/P:1 Clothing 31411 Computers 91611 Textbooks 21312
2 Clothing 32522 Computers 12322 Supplies 22422 Text books 15462
O/P:
2 Computers 1232
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
27/56
27
WEEK5
a) Write A shell script that takes a command line argument and reports onwhether it is directry ,a file,or something else
b) Write a shell script that accepts one or more file name as a arguments andconverts all of thenm to uppercase,provided they exits in the current directoryc) Write a shell script that determines the period for which a specified user isworking on the system
(a) Sol:
echo "Enter a file name:"read f if [ -f $f ]thenecho "File"elif [ -d $f ]thenecho "Directory"elseecho "Not"fi
Output:
Directory
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
28/56
28
WEEK6
(a) Write a shell script that accepts a file name starting and ending line numbersas arguments and displays all the lines between the given line numbers(b) Write a shell script that deletes all lines containing a specified word I one or
more files supplied as arguments to it.
(a) Sol:
$ awk NR 4 {print $0} 5 lines.dat
I/P: line1
line2line3line4line5
O/P: line1line5
(b) Sol:
i=1while [ $i -le $# ]do
grep -v Unix $i > $i
done
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
29/56
29
WEEK7
a) Write a shell script that computes the gross salary of a employee according to thefollowing
1) if basic salary is 1500 then HRA 500 and DA =98% of the basicThe basic salary is entered interactively through the key board
(b)Write a shell script that accepts two integers as its arguments and computesthe value of first number raised to the power of the second number
echo " Enter the Salary "read salif [ $sal1500]hra=500da=expr $sal*98/100gsal=expr $sal+$hra+$dagross=`expr $sa + $da + $hra`fifi
(b)a=$1
b=$2c=pow($a,$b)echo$c
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
30/56
30
WEEK 8
(a) Write an interactive file handling shell program. Let it offer the user thechoice of copying ,removing ,renaming or linking files. Once the use has made a
choice, have the program ask the user for necessary information, such as the filename ,new name and so on.(b) Write a shell script that takes a login name as command line argument andreports when that person logs in(c) Write a shell script which receives two files names as arguments. It shouldcheck whether the two file contents are same or not. If they are same then secondfile should be deleted.
PROGRAM
echo "Enter I File Name:"read f1echo "Enter II File Name:"read f2d=`cmp $f1 $f2`d1=""if [ $d -eq $d2 ]then
echo "Two Files are similar and $f2 is deleted"rm $f2
elseecho "Two Files differ each other"
fi
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
31/56
31
WEEK 9(a) Write a shell script that displays a list of all files in the current directory towhich the user has read write and execute permissions(b) Develop an interactive script that asks for a word and file name and thentells how many times that word occurred in the file.
(c) Write a shell script to perform the following string operations.1) To extract a sub string from a given string2) To find the length of a given string
(a) PROGRAM
# File Name : list.sh
#!/bin/bashread -p "Enter a directory name : " dnif [ -d $dn ]; then
printf "\nFiles in the directory $dn are :\n"for fn in `ls $dn`doif [ -d $dn/$fn ]; then
printf " Directory "elif [ -f $dn/$fn ]
thenprintf "$fn File "
fiif [ -r $dn/$fn ]; then
printf " Read"fi
if [ -w $dn/$fn ];then
printf " Write"fi
if [ -x $dn/$fn ];then
printf " Execute"fiprintf "\n"
doneelseprintf "\n$dn not exists or not a directory"
fi
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
32/56
32
(b) PROGRAM
# File Name : wcount.sh#!/bin/bash
read -p "Enter a file name : " fnif test -f $fnthenecho "The contents of the file $fn is :"cat $fnecho "No. of Line : `wc -l $fn`"echo "No. of Words : `wc -w $fn`"echo "No. of Characters: `wc -c $fn`"
elseecho "$fn is not exists or not a file"
fi
(c) PROGRAM
Print Enter the String:\cread strInstrlen=${# strIn}
print the string length is : $strlen$ strlen.scr
O/P:Enter the String: Now is the timeThe String length : 15
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
33/56
33
WEEK 10
Write a C program that takes one or more file or directory names as command lineinput and reports the following information on the file.
1. file type2. number of links3. read, write and execute permissions4. time of last access
(Note: use /fstat system calls)
PROGRAM
#includemain()
{FILE *stream;int buffer_character;stream=fopen(test,r);if(stream==(FILE*)0){fprintf(stderr,Error opening file(printed to standard error)\n);fclose(stream);exit(1);}}
if(fclose(stream))==EOF){fprintf(stderr,Error closing stream.(printed to standard error)\n);exit(1);}return();}
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
34/56
34
WEEK 11
Write C program that simulate the following unix commands(a) mv(b) cp
/* File Name : bspace1.c */#include#include#includemain(int argc,char *argv[]){FILE *fp;char ch;int sc=0;
fp=fopen(argv[1],"r");if(fp==NULL)
printf("unable to open a file",argv[1]);else{
while(!feof(fp)){ch=fgetc(fp);if(ch==' ')sc++;
}printf("no of spaces %d",sc);printf("\n");fclose(fp);
}}
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
35/56
35
WEEK 12
Write a c program that simulates ls command(Use system calls /directory API)
PROGRAM:
#include#include#includemain(int argc,char *argv[]){
int fd,i;char ch[1];
if (argc0)
printf("%c",ch[0]);close(fd);}
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
36/56
36
Viva Questions & Answers
What is a Make file?
Make file is a utility in Unix to help compile large programs. It helps by only compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel?
The kernel is the heart of the UNIX operating system , itsresponsible for controlling the computers resources andscheduling user jobs so that each one gets its fair share of resources.
How can you tell what shell you are running on UNIXsystem?
You can do the Echo $RANDOM. It will return a undefinedvariable if you are from the C-Shell, just a return prompt if youare from the Bourne shell, and a 5 digit random numbers if youare from the Korn shell. You could also do a ps -l and look for the shell with []
What do you mean by u-area (user area) or u-block?This contains the private data that is manipulated only by theKernel. This is local to the Process, i.e. each process isallocated a u-area.
What scheme does the Kernel in Unix System V follow whilechoosing a swap device among the multiple swap devices?
Kernel follows Round Robin scheme choosing a swap deviceamong the multiple swap devices in Unix System V.
List the system calls used for process management:
System calls Descriptionfork() To create a new processexec() To execute a new program in a processwait() []
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/unix-interview-questions/what-is-a-make-file-2/http://kyapoocha.com/category/unix-interview-questions/http://kyapoocha.com/unix-interview-questions/could-you-tell-something-about-the-unix-system-kernel/http://kyapoocha.com/category/unix-interview-questions/http://kyapoocha.com/category/unix-interview-questions/http://kyapoocha.com/unix-interview-questions/how-can-you-tell-what-shell-you-are-running-on-unix-system-2/http://kyapoocha.com/unix-interview-questions/how-can-you-tell-what-shell-you-are-running-on-unix-system-2/http://kyapoocha.com/unix-interview-questions/what-do-you-mean-by-u-area-user-area-or-u-block/http://kyapoocha.com/unix-interview-questions/what-scheme-does-the-kernel-in-unix-system-v-follow-while-choosing-a-swap-device-among-the-multiple-swap-devices/http://kyapoocha.com/unix-interview-questions/what-scheme-does-the-kernel-in-unix-system-v-follow-while-choosing-a-swap-device-among-the-multiple-swap-devices/http://kyapoocha.com/category/unix-interview-questions/http://kyapoocha.com/category/unix-interview-questions/http://kyapoocha.com/unix-interview-questions/list-the-system-calls-used-for-process-management/http://kyapoocha.com/unix-interview-questions/what-is-a-make-file-2/http://kyapoocha.com/category/unix-interview-questions/http://kyapoocha.com/unix-interview-questions/could-you-tell-something-about-the-unix-system-kernel/http://kyapoocha.com/category/unix-interview-questions/http://kyapoocha.com/unix-interview-questions/how-can-you-tell-what-shell-you-are-running-on-unix-system-2/http://kyapoocha.com/unix-interview-questions/how-can-you-tell-what-shell-you-are-running-on-unix-system-2/http://kyapoocha.com/unix-interview-questions/what-do-you-mean-by-u-area-user-area-or-u-block/http://kyapoocha.com/unix-interview-questions/what-scheme-does-the-kernel-in-unix-system-v-follow-while-choosing-a-swap-device-among-the-multiple-swap-devices/http://kyapoocha.com/unix-interview-questions/what-scheme-does-the-kernel-in-unix-system-v-follow-while-choosing-a-swap-device-among-the-multiple-swap-devices/http://kyapoocha.com/category/unix-interview-questions/http://kyapoocha.com/unix-interview-questions/list-the-system-calls-used-for-process-management/ -
8/9/2019 UNIX Labmanual
37/56
37
How do you change File Access Permissions?
Every file has following attributes:owners user ID ( 16 bit integer )owners group ID ( 16 bit integer )
File access mode wordr w x -r w x- r w x(user permission-group permission-others permission)r-read, w-write, x-executeTo change the access mode, we use chmod(filename,mode).Example:To change mode of myfile to rw-rw-r (ie. read, writepermission for user - []
Explain the layered aspect of a UNIX system. What are thelayers? What does it mean to say they are layers?
A UNIX system has essentially three main layers:. The hardware. The operating system kernel. The user-level programsThe kernel hides the systems hardware underneath anabstract, high-level programming interface. It is responsible for implementing many of the facilities that users and user-levelprograms take for granted.The kernel assembles all of the following UNIX concepts fromlower-level []
What is the use of grep command?
grep is a pattern search command. It searches for the pattern,specified in the command line with appropriate option, in afile(s).Syntax : grep Example : grep 99mx mcafile
What difference between cmp and diff commands?
cmp - Compares two files byte by byte and displays the firstmismatchdiff - tells the changes to be made to make the files identical
What is the significance of the tee command?
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/unix-interview-questions/how-do-you-change-file-access-permissions/http://kyapoocha.com/category/unix-interview-questions/http://kyapoocha.com/unix-interview-questions/explain-the-layered-aspect-of-a-unix-system-what-are-the-layers-what-does-it-mean-to-say-they-are-layers/http://kyapoocha.com/unix-interview-questions/explain-the-layered-aspect-of-a-unix-system-what-are-the-layers-what-does-it-mean-to-say-they-are-layers/http://kyapoocha.com/category/unix-interview-questions/page/2/http://kyapoocha.com/category/unix-interview-questions/page/2/http://kyapoocha.com/category/unix-interview-questions/page/2/http://kyapoocha.com/unix-interview-questions/what-is-the-use-of-%E2%80%98grep%E2%80%99-command/http://kyapoocha.com/unix-interview-questions/what-difference-between-cmp-and-diff-commands/http://kyapoocha.com/unix-interview-questions/what-is-the-significance-of-the-%E2%80%9Ctee%E2%80%9D-command/http://kyapoocha.com/unix-interview-questions/how-do-you-change-file-access-permissions/http://kyapoocha.com/category/unix-interview-questions/http://kyapoocha.com/unix-interview-questions/explain-the-layered-aspect-of-a-unix-system-what-are-the-layers-what-does-it-mean-to-say-they-are-layers/http://kyapoocha.com/unix-interview-questions/explain-the-layered-aspect-of-a-unix-system-what-are-the-layers-what-does-it-mean-to-say-they-are-layers/http://kyapoocha.com/category/unix-interview-questions/page/2/http://kyapoocha.com/category/unix-interview-questions/page/2/http://kyapoocha.com/category/unix-interview-questions/page/2/http://kyapoocha.com/unix-interview-questions/what-is-the-use-of-%E2%80%98grep%E2%80%99-command/http://kyapoocha.com/unix-interview-questions/what-difference-between-cmp-and-diff-commands/http://kyapoocha.com/unix-interview-questions/what-is-the-significance-of-the-%E2%80%9Ctee%E2%80%9D-command/ -
8/9/2019 UNIX Labmanual
38/56
38
It reads the standard input and sends it to the standard outputwhile redirecting a copy of what it has read to the file specifiedby the user.
Is du a command? If so, what is its use?
Yes, it stands for disk usage. With the help of this commandyou can find the disk capacity and free space of the disk.
How to terminate a process which is running and thespecialty on command kill 0?
With the help of kill command we can terminate the process.Syntax: kill pid Kill 0 - kills all processes in your system exceptthe login shell.
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/unix-interview-questions/is-%E2%80%98du%E2%80%99-a-command-if-so-what-is-its-use/http://kyapoocha.com/category/unix-interview-questions/page/2/http://kyapoocha.com/unix-interview-questions/how-to-terminate-a-process-which-is-running-and-the-specialty-on-command-kill-0/http://kyapoocha.com/unix-interview-questions/how-to-terminate-a-process-which-is-running-and-the-specialty-on-command-kill-0/http://kyapoocha.com/unix-interview-questions/is-%E2%80%98du%E2%80%99-a-command-if-so-what-is-its-use/http://kyapoocha.com/category/unix-interview-questions/page/2/http://kyapoocha.com/unix-interview-questions/how-to-terminate-a-process-which-is-running-and-the-specialty-on-command-kill-0/http://kyapoocha.com/unix-interview-questions/how-to-terminate-a-process-which-is-running-and-the-specialty-on-command-kill-0/ -
8/9/2019 UNIX Labmanual
39/56
39
Explain kill() and its possible return values.
There are four possible results from this call:kill() returns 0. This implies that a process exists with the given
PID, and the system would allow you to send signals to it. It issystem-dependent whether the process could be a zombie.kill() returns -1, errno == ESRCH either no process exists withthe given PID, or []
What does the command $who | sort logfile > newfiledo?
The input from a pipe can be combined with the input from afile . The trick is to use the special symbol - (a hyphen) for those commands that recognize the hyphen as std input.In the above command the output from who becomes the stdinput to sort , meanwhile sort opens the file []
What are shell variables?
Shell variables are special variables, a name-value pair createdand maintained by the shell.Example: PATH, HOME, MAIL and TERM
How many prompts are available in a UNIX system?
Two prompts, PS1 (Primary Prompt), PS2 (Secondary Prompt).
Is it possible to create new a file system in UNIX?
Use su command. The system asks for password and whenvalid entry is made the user gains super user (admin) privileges.
How the Kernel handles the copy on write bit of a page,when the bit is set?
In situations like, where the copy on write bit of a page is setand that page is shared by more than one process, the Kernelallocates new page and copies the content to the new page andthe other processes retain their references to the old page. After copying the Kernel updates the page []
Difference between the fork() and vfork() system call?
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/unix-interview-questions/explain-kill-and-its-possible-return-values/http://kyapoocha.com/unix-interview-questions/what-does-the-command-%E2%80%9C-who-sort-%E2%80%93logfile-newfile%E2%80%9D-do/http://kyapoocha.com/unix-interview-questions/what-does-the-command-%E2%80%9C-who-sort-%E2%80%93logfile-newfile%E2%80%9D-do/http://kyapoocha.com/unix-interview-questions/what-are-shell-variables/http://kyapoocha.com/unix-interview-questions/how-many-prompts-are-available-in-a-unix-system/http://kyapoocha.com/unix-interview-questions/is-it-possible-to-create-new-a-file-system-in-unix/http://kyapoocha.com/unix-interview-questions/how-the-kernel-handles-the-copy-on-write-bit-of-a-page-when-the-bit-is-set/http://kyapoocha.com/unix-interview-questions/how-the-kernel-handles-the-copy-on-write-bit-of-a-page-when-the-bit-is-set/http://kyapoocha.com/unix-interview-questions/difference-between-the-fork-and-vfork-system-call/http://kyapoocha.com/unix-interview-questions/explain-kill-and-its-possible-return-values/http://kyapoocha.com/unix-interview-questions/what-does-the-command-%E2%80%9C-who-sort-%E2%80%93logfile-newfile%E2%80%9D-do/http://kyapoocha.com/unix-interview-questions/what-does-the-command-%E2%80%9C-who-sort-%E2%80%93logfile-newfile%E2%80%9D-do/http://kyapoocha.com/unix-interview-questions/what-are-shell-variables/http://kyapoocha.com/unix-interview-questions/how-many-prompts-are-available-in-a-unix-system/http://kyapoocha.com/unix-interview-questions/is-it-possible-to-create-new-a-file-system-in-unix/http://kyapoocha.com/unix-interview-questions/how-the-kernel-handles-the-copy-on-write-bit-of-a-page-when-the-bit-is-set/http://kyapoocha.com/unix-interview-questions/how-the-kernel-handles-the-copy-on-write-bit-of-a-page-when-the-bit-is-set/http://kyapoocha.com/unix-interview-questions/difference-between-the-fork-and-vfork-system-call/ -
8/9/2019 UNIX Labmanual
40/56
40
During the fork() system call the Kernel makes a copy of the parent processs addressspace and attaches it to the child process.But the vfork() system call do not makes anycopy of the parents address space, so it is faster than the fork() system call. The child
process as a result of the vfork() []
How the Kernel handles the fork() system call in traditionalUnix and in the System V Unix, while swapping?
Kernel in traditional Unix, makes the duplicate copy of theparents address space and attaches it to the childs process,while swapping. Kernel in System V Unix, manipulates theregion tables, page table, and pfdata table entries, byincrementing the reference count of the region table of sharedregions.
What are the requirements for a swapper to work?
The swapper works on the highest scheduling priority. Firstly itwill look for any sleeping process, if not found then it will look for the ready-to-run process for swapping. But the major requirement for the swapper to work the ready-to-run processmust be core-resident for at least 2 seconds before swappingout. And for swapping []
What is Expansion swap?
At the time when any process requires more memory than it iscurrently allocated, the Kernel performs Expansion swap. To dothis Kernel reserves enough space in the swap device. Then theaddress translation mapping is adjusted for the new virtualaddress space but the physical memory is not allocated. At lastKernel swaps the []
What is Fork swap?
fork() is a system call to create a child process. When the parentprocess calls fork() system call, the child process is created andif there is short of memory then the child process is sent to theread-to-run state in the swap device, and return to the user statewithout swapping the parent process. []
What are the entities that are swapped out of the mainmemory while swapping the process out of the mainmemory?
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/unix-interview-questions/how-the-kernel-handles-the-fork-system-call-in-traditional-unix-and-in-the-system-v-unix-while-swapping/http://kyapoocha.com/unix-interview-questions/how-the-kernel-handles-the-fork-system-call-in-traditional-unix-and-in-the-system-v-unix-while-swapping/http://kyapoocha.com/unix-interview-questions/what-are-the-requirements-for-a-swapper-to-work/http://kyapoocha.com/unix-interview-questions/what-is-expansion-swap/http://kyapoocha.com/unix-interview-questions/what-is-fork-swap/http://kyapoocha.com/unix-interview-questions/what-are-the-entities-that-are-swapped-out-of-the-main-memory-while-swapping-the-process-out-of-the-main-memory/http://kyapoocha.com/unix-interview-questions/what-are-the-entities-that-are-swapped-out-of-the-main-memory-while-swapping-the-process-out-of-the-main-memory/http://kyapoocha.com/unix-interview-questions/what-are-the-entities-that-are-swapped-out-of-the-main-memory-while-swapping-the-process-out-of-the-main-memory/http://kyapoocha.com/unix-interview-questions/how-the-kernel-handles-the-fork-system-call-in-traditional-unix-and-in-the-system-v-unix-while-swapping/http://kyapoocha.com/unix-interview-questions/how-the-kernel-handles-the-fork-system-call-in-traditional-unix-and-in-the-system-v-unix-while-swapping/http://kyapoocha.com/unix-interview-questions/what-are-the-requirements-for-a-swapper-to-work/http://kyapoocha.com/unix-interview-questions/what-is-expansion-swap/http://kyapoocha.com/unix-interview-questions/what-is-fork-swap/http://kyapoocha.com/unix-interview-questions/what-are-the-entities-that-are-swapped-out-of-the-main-memory-while-swapping-the-process-out-of-the-main-memory/http://kyapoocha.com/unix-interview-questions/what-are-the-entities-that-are-swapped-out-of-the-main-memory-while-swapping-the-process-out-of-the-main-memory/http://kyapoocha.com/unix-interview-questions/what-are-the-entities-that-are-swapped-out-of-the-main-memory-while-swapping-the-process-out-of-the-main-memory/ -
8/9/2019 UNIX Labmanual
41/56
41
All memory space occupied by the process, processs u-area,and Kernel stack are swapped out, theoretically.Practically, if the processs u-area contains the AddressTranslation Tables for the process then Kernel implementationsdo not swap the u-area.
Is the Process before and after the swap are the same? Give reason.
Process before swapping is residing in the primary memory inits original form. The regions (text, data and stack) may not beoccupied fully by the process, there may be few empty slots inany of the regions and while swapping Kernel do not bother about the empty slots while swapping the process outAfter swapping []
What are the events done by the Kernel after a process isbeing swapped out from the main memory?
When Kernel swaps the process out of the primary memory, itperforms the following:Kernel decrements the Reference Count of each region of theprocess. If the reference count becomes zero, swaps the regionout of the main memory.Kernel allocates the space for the swapping process in the swapdevice.Kernel locks the other swapping process while []
What is major difference between the Historic Unix and thenew BSD release of Unix System V in terms of MemoryManagement?
Historic Unix uses Swapping entire process is transferred tothe main memory from the swap device, whereas the UnixSystem V uses Demand Paging only the part of the process ismoved to the main memory. Historic Unix uses one SwapDevice and Unix System V allow multiple Swap Devices
What is an advantage of executing a process inbackground?
The most common reason to put a process in the background isto allow you to do something else interactively without waitingfor the process to complete. At the end of the command you addthe special background symbol, &. This symbol tells your shell
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/unix-interview-questions/is-the-process-before-and-after-the-swap-are-the-same-give-reason/http://kyapoocha.com/unix-interview-questions/is-the-process-before-and-after-the-swap-are-the-same-give-reason/http://kyapoocha.com/unix-interview-questions/what-are-the-events-done-by-the-kernel-after-a-process-is-being-swapped-out-from-the-main-memory/http://kyapoocha.com/unix-interview-questions/what-are-the-events-done-by-the-kernel-after-a-process-is-being-swapped-out-from-the-main-memory/http://kyapoocha.com/unix-interview-questions/what-is-major-difference-between-the-historic-unix-and-the-new-bsd-release-of-unix-system-v-in-terms-of-memory-management/http://kyapoocha.com/unix-interview-questions/what-is-major-difference-between-the-historic-unix-and-the-new-bsd-release-of-unix-system-v-in-terms-of-memory-management/http://kyapoocha.com/unix-interview-questions/what-is-major-difference-between-the-historic-unix-and-the-new-bsd-release-of-unix-system-v-in-terms-of-memory-management/http://kyapoocha.com/unix-interview-questions/what-is-an-advantage-of-executing-a-process-in-background/http://kyapoocha.com/unix-interview-questions/what-is-an-advantage-of-executing-a-process-in-background/http://kyapoocha.com/unix-interview-questions/is-the-process-before-and-after-the-swap-are-the-same-give-reason/http://kyapoocha.com/unix-interview-questions/is-the-process-before-and-after-the-swap-are-the-same-give-reason/http://kyapoocha.com/unix-interview-questions/what-are-the-events-done-by-the-kernel-after-a-process-is-being-swapped-out-from-the-main-memory/http://kyapoocha.com/unix-interview-questions/what-are-the-events-done-by-the-kernel-after-a-process-is-being-swapped-out-from-the-main-memory/http://kyapoocha.com/unix-interview-questions/what-is-major-difference-between-the-historic-unix-and-the-new-bsd-release-of-unix-system-v-in-terms-of-memory-management/http://kyapoocha.com/unix-interview-questions/what-is-major-difference-between-the-historic-unix-and-the-new-bsd-release-of-unix-system-v-in-terms-of-memory-management/http://kyapoocha.com/unix-interview-questions/what-is-major-difference-between-the-historic-unix-and-the-new-bsd-release-of-unix-system-v-in-terms-of-memory-management/http://kyapoocha.com/unix-interview-questions/what-is-an-advantage-of-executing-a-process-in-background/http://kyapoocha.com/unix-interview-questions/what-is-an-advantage-of-executing-a-process-in-background/ -
8/9/2019 UNIX Labmanual
42/56
42
to execute the given command in the background.Example: cp *.* []
What Happens when you execute a program?
When you execute a program on your UNIX system, the systemcreates a special environment for that program. Thisenvironment contains everything needed for the system to runthe program as if no other program were running on the system.Each process has process context, which is everything that isunique about the state of []
What are the process states in Unix?
As a process executes it changes state according to itscircumstances. 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 asignal.Zombie : The []
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/unix-interview-questions/what-happens-when-you-execute-a-program/http://kyapoocha.com/unix-interview-questions/what-are-the-process-states-in-unix/http://kyapoocha.com/unix-interview-questions/what-happens-when-you-execute-a-program/http://kyapoocha.com/unix-interview-questions/what-are-the-process-states-in-unix/ -
8/9/2019 UNIX Labmanual
43/56
43
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 mayneed to check the childs exit status. To be able to get thisinformation, the parent calls `wait(); In the []
How can a parent and child process communicate?
A parent and child can communicate through any of the normalinter-process communication schemes (pipes, sockets,message queues, shared memory), but also have some specialways to communicate that take advantage of their relationshipas a parent and child. One of the most obvious is that the parent
can get the exit status of the []
How can you get/set an environment variable from aprogram?
Getting the value of an environment variable is done by using`getenv().Setting the value of an environment variable is done by using`putenv().
Explain fork() system call.
The `fork() used to create a new process from an existingprocess. The new process is called the child process, and theexisting process is called the parent. We can tell which is whichby checking the return value from fork(). The parent gets thechilds pid returned to him, but []
What are various IDs associated with a process?
Unix identifies each process with a unique integer calledProcessID. The process that executes the request for creationof a process is called the parent process whose PID is ParentProcess ID. Every process is associated with a particular user called the owner who has privileges over the process. Theidentification for the user is []
Brief about the initial process sequence while the systemboots up.
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/unix-interview-questions/what-is-a-zombie/http://kyapoocha.com/unix-interview-questions/how-can-a-parent-and-child-process-communicate/http://kyapoocha.com/unix-interview-questions/how-can-you-getset-an-environment-variable-from-a-program/http://kyapoocha.com/unix-interview-questions/how-can-you-getset-an-environment-variable-from-a-program/http://kyapoocha.com/unix-interview-questions/explain-fork-system-call/http://kyapoocha.com/unix-interview-questions/what-are-various-ids-associated-with-a-process/http://kyapoocha.com/unix-interview-questions/brief-about-the-initial-process-sequence-while-the-system-boots-up/http://kyapoocha.com/unix-interview-questions/brief-about-the-initial-process-sequence-while-the-system-boots-up/http://kyapoocha.com/unix-interview-questions/what-is-a-zombie/http://kyapoocha.com/unix-interview-questions/how-can-a-parent-and-child-process-communicate/http://kyapoocha.com/unix-interview-questions/how-can-you-getset-an-environment-variable-from-a-program/http://kyapoocha.com/unix-interview-questions/how-can-you-getset-an-environment-variable-from-a-program/http://kyapoocha.com/unix-interview-questions/explain-fork-system-call/http://kyapoocha.com/unix-interview-questions/what-are-various-ids-associated-with-a-process/http://kyapoocha.com/unix-interview-questions/brief-about-the-initial-process-sequence-while-the-system-boots-up/http://kyapoocha.com/unix-interview-questions/brief-about-the-initial-process-sequence-while-the-system-boots-up/ -
8/9/2019 UNIX Labmanual
44/56
44
While booting, special process called the swapper or scheduler is created with Process-ID 0. The swapper managesmemory 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. []
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
-
8/9/2019 UNIX Labmanual
45/56
45
What is a shell?
A shell is an interactive user interface to an operating systemservices 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 aprocess to execute the command. System call results and other information from the OS []
How does the inode map to data block of a file?
Inode has 13 block addresses. The first 10 are direct blockaddresses of the first 10 data blocks in the file. The 11thaddress points to a one-level index block. The 12th addresspoints 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 []
Discuss the mount and unmount system calls
The privileged mount system call is used to attach a file systemto a directory of another file system; the unmount system calldetaches a file system. When you mount another file system onto your directory, you are essentially splicing one directory treeonto a branch in another directory tree. The first argument to[]
How do you create special files like named pipes and device files?
The system call mknod creates special files in the followingsequence.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 []
What are links and symbolic links in UNIX file system?
A link is a second name (not a file) for a file. Links can be usedto assign more than one name to a file, but cannot be used toassign a directory more than one name or link filenames ondifferent computers.
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/unix-interview-questions/what-is-a-shell/http://kyapoocha.com/unix-interview-questions/how-does-the-inode-map-to-data-block-of-a-file/http://kyapoocha.com/unix-interview-questions/discuss-the-mount-and-unmount-system-calls/http://kyapoocha.com/unix-interview-questions/how-do-you-create-special-files-like-named-pipes-and-device-files/http://kyapoocha.com/unix-interview-questions/how-do-you-create-special-files-like-named-pipes-and-device-files/http://kyapoocha.com/unix-interview-questions/what-are-links-and-symbolic-links-in-unix-file-system/http://kyapoocha.com/unix-interview-questions/what-is-a-shell/http://kyapoocha.com/unix-interview-questions/how-does-the-inode-map-to-data-block-of-a-file/http://kyapoocha.com/unix-interview-questions/discuss-the-mount-and-unmount-system-calls/http://kyapoocha.com/unix-interview-questions/how-do-you-create-special-files-like-named-pipes-and-device-files/http://kyapoocha.com/unix-interview-questions/how-do-you-create-special-files-like-named-pipes-and-device-files/http://kyapoocha.com/unix-interview-questions/what-are-links-and-symbolic-links-in-unix-file-system/ -
8/9/2019 UNIX Labmanual
46/56
46
Symbolic link is a file that only contains the name of another file.Operation []
What are the Unix system calls for I/O?
open(pathname,flag,mode) - open filecreat(pathname,mode) - create fileclose(filedes) - close an open fileread(filedes,buffer,bytes) - read data from an open filewrite(filedes,buffer,bytes) - write data to an open filelseek(filedes,offset,from) - position an open filedup(filedes) - duplicate an existing file descriptor dup2(oldfd,newfd) - duplicate to a desired file descriptor fcntl(filedes,cmd,arg) - change properties of an open fileioctl(filedes,request,arg) - change the behaviour []
What Happens when you execute a program?When you execute a program on your UNIX system , thesystem creates a special environment for that program. Thisenvironment contains everything needed for the system to runthe program as if no other program were running on the system.Each process has process context, which is everything that isunique about the state of []
What are the process states in Unix?
As a process executes it changes state according to itscircumstances. 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 asignal.Zombie : The []
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 incase the parent might need it - for example, the parent mayneed to check the childs exit status. To be able to get thisinformation, the parent calls `wait(); In the []
How can a parent and child process communicate?
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/unix-interview-questions/what-are-the-unix-system-calls-for-io/http://kyapoocha.com/unix-interview-questions/what-happens-when-you-execute-a-program/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/what-are-the-process-states-in-unix/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/what-is-a-zombie/http://kyapoocha.com/unix-interview-questions/how-can-a-parent-and-child-process-communicate/http://kyapoocha.com/unix-interview-questions/what-are-the-unix-system-calls-for-io/http://kyapoocha.com/unix-interview-questions/what-happens-when-you-execute-a-program/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/what-are-the-process-states-in-unix/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/what-is-a-zombie/http://kyapoocha.com/unix-interview-questions/how-can-a-parent-and-child-process-communicate/ -
8/9/2019 UNIX Labmanual
47/56
47
A parent and child can communicate through any of the normalinter-process communication schemes (pipes, sockets,message queues, shared memory), but also have some specialways to communicate that take advantage of their relationshipas a parent and child. One of the most obvious is that the parent
can get the exit status of the []
How can you get/set an environment variable from aprogram?
Getting the value of an environment variable is done byusing `getenv().Setting the value of an environment variable is done by using`putenv().
Explain fork() system call.
The `fork() used to create a new process from an existingprocess. The new process is called the child process, and theexisting process is called the parent. We can tell which is whichby checking the return value from fork(). The parent gets thechilds pid returned to him, but []
What are various IDs associated with a process?
Unix identifies each process with a unique integer calledProcessID. The process that executes the request for creationof a process is called the parent process whose PID is ParentProcess ID. Every process is associated with a particular user called the owner who has privileges over the process. Theidentification for the user is []
Brief about the initial process sequence while the systemboots up.
While booting, special process called the swapper or scheduler is created with Process-ID 0. The swapper managesmemory allocation for processes and influences CPU allocation.The swapper inturn creates 3 children:the process dispatcher,vhand and dbflush with IDs 1,2 and 3respectively.This is done by executing the file /etc/init. Process dispatcher gives birth to the shell. []
What is a shell?
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/unix-interview-questions/how-can-you-getset-an-environment-variable-from-a-program/http://kyapoocha.com/unix-interview-questions/how-can-you-getset-an-environment-variable-from-a-program/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/explain-fork-system-call/http://kyapoocha.com/unix-interview-questions/what-are-various-ids-associated-with-a-process/http://kyapoocha.com/unix-interview-questions/brief-about-the-initial-process-sequence-while-the-system-boots-up/http://kyapoocha.com/unix-interview-questions/brief-about-the-initial-process-sequence-while-the-system-boots-up/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/what-is-a-shell/http://kyapoocha.com/unix-interview-questions/how-can-you-getset-an-environment-variable-from-a-program/http://kyapoocha.com/unix-interview-questions/how-can-you-getset-an-environment-variable-from-a-program/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/explain-fork-system-call/http://kyapoocha.com/unix-interview-questions/what-are-various-ids-associated-with-a-process/http://kyapoocha.com/unix-interview-questions/brief-about-the-initial-process-sequence-while-the-system-boots-up/http://kyapoocha.com/unix-interview-questions/brief-about-the-initial-process-sequence-while-the-system-boots-up/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/what-is-a-shell/ -
8/9/2019 UNIX Labmanual
48/56
48
A shell is an interactive user interface to an operatingsystem services that allows an user to enter commands ascharacter strings or through a graphical user interface .The shell converts them to system calls to the OS or forks off aprocess to execute the command. System call results and other
information from the OS []
How does the inode map to data block of a file?
Inode has 13 block addresses. The first 10 are direct blockaddresses of the first 10 data blocks in the file. The 11thaddress points to a one-level index block. The 12th addresspoints to a two-level (double in-direction) index block. The 13thaddress points to a three-level(triple in-direction)index block.This provides a very large maximum []
Discuss the mount and unmount system callsThe privileged mount system call is used to attach a filesystem to a directory of another file system; the unmountsystem call detaches a file system. When you mount another filesystem on to your directory, you are essentially splicing onedirectory tree onto a branch in another directory tree. The firstargument to []
How do you create special files like named pipes and device files?
The system call mknod creates special files in the followingsequence.1. kernel assigns new inode,2. sets the file type to indicate that the file is a pipe, directoryor 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 []
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 datais read from named pipe, it cannot be read again.Also, data can be read only in the order written. It is used ininterprocess communication where a process writes to one endof []
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/how-does-the-inode-map-to-data-block-of-a-file/http://kyapoocha.com/unix-interview-questions/discuss-the-mount-and-unmount-system-calls/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/how-do-you-create-special-files-like-named-pipes-and-device-files/http://kyapoocha.com/unix-interview-questions/how-do-you-create-special-files-like-named-pipes-and-device-files/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/what-is-a-fifo/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/how-does-the-inode-map-to-data-block-of-a-file/http://kyapoocha.com/unix-interview-questions/discuss-the-mount-and-unmount-system-calls/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/how-do-you-create-special-files-like-named-pipes-and-device-files/http://kyapoocha.com/unix-interview-questions/how-do-you-create-special-files-like-named-pipes-and-device-files/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/what-is-a-fifo/ -
8/9/2019 UNIX Labmanual
49/56
49
What are links and symbolic links in UNIX file system?
A link is a second name (not a file) for a file. Links can be usedto assign more than one name to a file, but cannot be used toassign a directory more than one name or link filenames on
different computers .Symbolic link is a file that only contains the name of another file.Operation []
What are the Unix system calls for I/O?
open(pathname,flag,mode) - open filecreat(pathname,mode) - create fileclose(filedes) - close an open fileread(filedes,buffer,bytes) - read data from an open filewrite(filedes,buffer,bytes) - write data to an open file
lseek(filedes,offset,from) - position an open filedup(filedes) - duplicate an existing file descriptor dup2(oldfd,newfd) - duplicate to a desired file descriptor fcntl(filedes,cmd,arg) - change properties of an open fileioctl(filedes,request,arg) - change the behaviour []
Brief about the directory representation in UNIX
s a file containing a correspondence between filenames andinodes. A directory is a special file that the kernel maintains.Only kernel modifies directories , but processes can readdirectories. The contents of a directory are a list of filename andinode number pairs. When new directories are created, kernelmakes two entries []
What is inode?
All UNIX files have its description stored in a structure calledinode. The inode contains info about the file-size, its location,time of last access, time of last modification, permission and soon. Directories are also represented as files and have anassociated inode. In addition to descriptions about the file, theinode contains pointers []
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://kyapoocha.com/unix-interview-questions/what-are-links-and-symbolic-links-in-unix-file-system/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/what-are-the-unix-system-calls-for-io/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/brief-about-the-directory-representation-in-unix/http://kyapoocha.com/category/unix-interview-questions/page/5/http://kyapoocha.com/unix-interview-questions/what-is-inode/http://kyapoocha.com/unix-interview-questions/what-are-links-and-symbolic-links-in-unix-file-system/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/what-are-the-unix-system-calls-for-io/http://kyapoocha.com/category/unix-interview-questions/page/4/http://kyapoocha.com/unix-interview-questions/brief-about-the-directory-representation-in-unix/http://kyapoocha.com/category/unix-interview-questions/page/5/http://kyapoocha.com/unix-interview-questions/what-is-inode/ -
8/9/2019 UNIX Labmanual
50/56
-
8/9/2019 UNIX Labmanual
51/56
51
$cat >file means to create a new file $cat file means to openan existing file.
Answered By: selva, ravi Date: 7/13/2007
cat > file it means creating file for file cat file it means used to
display the file content
Explain the steps thata shell follows whileprocessing a command.
Answer
When processing a command the searchs for the utility forthe command in the directories specified in the PATH varibleand it in invokes that utility. That utility will execute thecommand with help of kernel and the output is given to shell.And then the displays out put to the user.
Explain the steps thata shell follows whileprocessing a command.
Answer
When processing a command the searchs for the utility forthe command in the directories specified in the PATH varibleand it in invokes that utility. That utility will execute thecommand with help of kernel and the output is given to shell.And then the displays out put to the user.
Which command isused to delete all filesin the current directoryand all its sub-directories ?
Answer
#rm -fr
# rm -rf *
Answered By: Amit Shiknis Date: 12/25/2007
rm -r *
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://newinterviewquestions.com/interview/7476/http://newinterviewquestions.com/interview/7475/http://newinterviewquestions.com/interview/7475/http://newinterviewquestions.com/interview/7475/http://newinterviewquestions.com/interview/7475/http://newinterviewquestions.com/interview/7474/http://newinterviewquestions.com/interview/7476/http://newinterviewquestions.com/interview/7475/http://newinterviewquestions.com/interview/7475/http://newinterviewquestions.com/interview/7475/http://newinterviewquestions.com/interview/7475/http://newinterviewquestions.com/interview/7474/ -
8/9/2019 UNIX Labmanual
52/56
52
What is the use of thecommand "ls -xchapter[1-5]"
AnswerYes you are correct. It stands for listing the files Chapter withsuffix 1 to 5 but it will display the files in columns as with-xoption.
How does the kerneldifferentiate devicefiles and ordinaryfiles?
Answer
Device filles are of 2 types --- charcater device file and blockdevice file
type field in the file's inode structure
b--- block device file
c--- character device file
How to switch to asuper user status togain privileges?
AnswerUse su command. The system asks for password and whenvalid entry is made the user gains super user (admin)privileges.
What are shell variables?
Answer Shell variables are system environment variables .Theyinclude
TERM,SHELL, MAIL
the output of the shell variable we can see by typing thecommand
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://newinterviewquestions.com/interview/7470/http://newinterviewquestions.com/interview/7469/http://newinterviewquestions.com/interview/7469/http://newinterviewquestions.com/interview/7470/http://newinterviewquestions.com/interview/7469/http://newinterviewquestions.com/interview/7469/ -
8/9/2019 UNIX Labmanual
53/56
53
$>echo $TERM
ansi
at the prompt.
What is redirection?
Answer
Redirection is a feature in Unix where the data from thestandard out put or a file,so on.can be redirected i.e divert toa file or a program and vice versa.
> -- out put redirection
>> -- out put redirectin(appending at the last)
< -- input redirection
How to terminate aprocess which isrunning and thespecialty on commandkill 0?
Answer
With the help of kill command we can terminate the process.Syntax: kill pidKill 0 - kills all processes in your system except the loginshell.
How to terminate aprocess which isrunning and thespecialty on commandkill 0?
Answer
With the help of kill command we can terminate the process.Syntax: kill pidKill 0 - kills all processes in your system except the loginshell.
How to sfind freespace in unix/ linux
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://newinterviewquestions.com/interview/7468/http://newinterviewquestions.com/interview/7464/http://newinterviewquestions.com/interview/7468/http://newinterviewquestions.com/interview/7464/ -
8/9/2019 UNIX Labmanual
54/56
54
Answer
Df and du commands are used for checking free space ondisk .df -h or df -Humanreadable gives human readable format of free space .
What is the differencebetween soft link andhard link in unixoperating system ?
Answer
Hard Links :
1. All Links have same inode number.
2.ls -l command shows all the links with the linkcolumn(Second) shows No. of links.
3. Links have actual file contents
4.Removing any link ,just reduces the link count , but doesn'taffect other links.
Soft Links(Symbolic Links) :
1.Links have different inode numbers.
2. ls -l command shows all links with second column value 1and the link points to original file.
3. Link has the path for original file and not the contents.
4.Removing soft link doesn't affect anything but removingoriginal file ,the link becomes "dangling" link which points tononexistant file.
to concatenate(attach) two strings?
Answer
For concatenating two string we use cat command.
Ex :- cat str1 str2
Explain the UNIX Kernel.
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://newinterviewquestions.com/interview/7464/http://newinterviewquestions.com/interview/7464/http://newinterviewquestions.com/interview/7464/http://newinterviewquestions.com/interview/7462/http://www.newinterviewquestions.com/interview/7457/http://www.newinterviewquestions.com/interview/7455/http://www.newinterviewquestions.com/interview/7455/http://newinterviewquestions.com/interview/7464/http://newinterviewquestions.com/interview/7464/http://newinterviewquestions.com/interview/7462/http://www.newinterviewquestions.com/interview/7457/http://www.newinterviewquestions.com/interview/7455/ -
8/9/2019 UNIX Labmanual
55/56
55
Answer
UNIX Kernel is heart of the operating system . UNIX kernal isloaded first when UNIX system is booted. It handles allocationof devices, cpu , memory from that ponint on.
How many prompts areavailable in a UNIXsystem ?
AnswerUnix / Linux Supports four Prompts PS1, PS2, PS3 , PS4
#,@,$,% are 4 prompts
REFERENCES :
Books:
1)Introduction to UNIX & SHELL programming, M.G. Venkatesh Murthy, Pearson Education.
2)Unix concepts and applications, Fourth Edition, Sumitabha Das, TMH.
Dept. of CSE (JNTU) UNIX & Shell Programming Lab 2009-10
http://www.newinterviewquestions.com/interview/7455/http://www.newinterviewquestions.com/interview/7455/http://www.newinterviewquestions.com/interview/7455/http://newinterviewquestions.com/interview/7472/http://newinterviewquestions.com/interview/7472/http://newinterviewquestions.com/interview/7472/http://newinterviewquestions.com/interview/7472/http://newinterviewquestions.com/interview/7472/http://www.newinterviewquestions.com/interview/7455/http://www.newinterviewquestions.com/interview/7455/http://newinterviewquestions.com/interview/7472/http://newinterviewquestions.com/interview/7472/http://newinterviewquestions.com/interview/7472/http://newinterviewquestions.com/interview/7472/ -
8/9/2019 UNIX Labmanual
56/56
56
3)Unix for programmers and users, 3 rd edition, Gaham Glass & K. Ables, pearson education.
4)Unix and shell Programming A text book, B.A. Forouzan & R.F. Giberg, Thomson.
5)Beginning shell scripting, E. Foster Johnson & other, Wile Y- India.