7
BC 0056- UNIX OPERATING SYSTEM NAME : Kumar Amitesh COURSE : BCA(5 th Sem) ROLL NO. : 511033236 SUBJECT : BC 0056-UNIX OPERATING SYSTEM LEARNING CENTRE : SMU LC-2017, New Delhi DATE OF SUBMISSION :

Unix

Embed Size (px)

Citation preview

Page 1: Unix

BC 0056- UNIX OPERATING SYSTEM

NAME : Kumar Amitesh

COURSE : BCA(5th Sem)

ROLL NO. : 511033236

SUBJECT : BC 0056-UNIX OPERATING SYSTEM

LEARNINGCENTRE : SMU LC-2017, New Delhi

DATE OF SUBMISSION :

Page 2: Unix

Spring 2012

Bachelor of Computer Application (BCA) – Semester 5

BC0056 – Unix Operating System – 4 Credits (Book ID: B0973) Assignment Set – 2 (40 Marks)

Each question carries Eight marks:

1. Explain Mounting and Un-mounting process in UNIX.Ans.: The file system is best visualized as a tree, rooted, at /., /dev, /usr and the other directories in the root directory are branches, having their own branches.The fstab File:During the boot process, file systems listed in /etc/fstab are automatically mounted. It contains the following list of lines:Device: An existing device name.Mount-point: A directory, on which to mount the file system.fstype: The file system type to pass to mount.Options: Either rw for read-write file systems, or ro for read only followed by any other options needed.dumpfreq: This is used by dump to determine which file systems require dumping.passno: This determines the order in which file systems should be checked.

The mount Command:The basic format of mount command: #mount device mountpoint Options:

-a: Mount all the file systems listed in /etc/fstab.-f: Forces the mount of an unclean file system(dangerous), or forces the revocationof write access when downgrading a file system's mount status from read-write to read-only.-r: Mounts the file system read-only.-t fstype: Mounts the given file system as the given file system type.-u: Update mounts options on the file system.-v: Be verbose.-w: Mounts the file system read-write.

Umount: Un-mounting File Systems:Unmounting is achieved with the unmount command which requires either the file system name or the mountpoint as argument.

umount/oracle umount/dev/hda3 umount/dev/dsk/c0t3d0s5

Page 3: Unix

2. Describe the various utilities used for taking back-up and compression activities.Ans.:UNIX systems usually support a number of utilities for backing up and compressing files. The most useful are:

tar(tape archiver): tar backs up entire directories and files onto a tape device or into a single disk file known as an archive. An archive is a file that contains other files plus information about them. tar does not perform any compression by default.Command to create a disk file tar archive is: $ tar -cvf archivenamefilenamesIt has a .tar extension.It has following options:-cvf: To create verbose file-tvf: To list the contents of tar archive-xvf: To restore files from a tar archive

cpio: It is another facility for creating and reading archives

compress, gzip: These two are utilities for compressing and decompressing individual files.The following commands are used: $ compress filename or $ gzip filenameIn each case, the filename will be deleted and replaced by a compressed file called filename.Z or filename.gz. To decompress, the following command is use: $ compress -d filename

3. Explain with an example the use of redirection input and output.Ans.: The processes usually write to standard output and take their input from standard input. There is another output channel called standard error, where processes write their error messages; by default error messages are also sent to the screen.To redirect standard output to a file instead of the screen, the > operator is used. eg. $ echo hello ← hello $ echo hello > output ← $ cat output ← helloIf we want to append the output of the echo command to the file, the >> operator is used. eg. $ echo bye >> output ← $ cat output ← hello byeTo capture standard error, prefix the > operator with a 2 eg. $ cat nonexistent 2>error ← $ cat errors ←

Page 4: Unix

cat: nonexistent: No such file or directory $Standard error can be redirected and standard output to two different files: $ find . -print 1>errors 2>files ←or to the same file: $ find . -print 1>output 2>output ←or $ find . -print >& output ←Standard input can also be redirected using the < operator, so that input is read from a file instead of the keyboard: $ cat < output hello byeInput redirection with output redirection can be combined together, but with different filename in both places. eg. $ cat < output > output ←It will destroy the contents of the file output.

4. Explain the use of sync and fsck.Ans.: sync:sync writes any data buffered in memory out to disk. This can include (but is not limited to) modified superblocks, modified inodes, and delayed reads and writes. This must be imple-mented by the kernel; The sync program does nothing but exercise the sync system call.

The kernel keeps data in memory to avoid doing (relatively slow) disk reads and writes. This improves performance, but if the computer crashes, data may be lost or the filesystem cor-rupted as a result. Sync ensures that everything in memory is written to disk.

Sync should be called before the processor is halted in an unusual manner (e.g., before causing a kernel panic when debugging new kernel code). In general, the processor should be halted using the shutdown or reboot or halt commands, which will attempt to put the sys-tem in a quiescent state before calling sync.Fsck is used to check and optionally repair one or more Linux file systems. filesys can be a device name a mount point, or an ext2 label or UUID specifier. Normally, the fsck program will try to run filesystems on different physical disk drives in parallel to reduce total amount time to check all of the filesystems.

If no filesystems are specified on the command line, and the -A option is not specified, fsck-will default to checking filesystems in /etc/fstab serial. This is equivalent to the -As options.

The exit code returned by fsck is the sum of the following conditions:0 - No errors 1 - File system errors corrected2 - System should be rebooted4 - File system errors left uncorrected8 - Operational error

Page 5: Unix

16 - Usage or syntax error32 - Fsck canceled by user request128 - Shared library errorThe exit code returned when multiple file systems are checked is the bit-wise OR of the exit codes for each file system that is checked.In actuality, fsck is simply a front-end for the vari-ous file system checkers (fsck.fstype) available under Linux. The file system-specific checker is searched for in /sbin first, then in/etc/fs and /etc, and finally in the directories listed in the PATH environment variable. Please see the file system-specific checker manual pages for fur-ther details.

5. Explain the use of following variables:IFS, PATH, LOGNAME, PROMPTAns.:IFS: IFS contains a string of characters that are used as word separators in the command line. The string normally consists of the space, tab and the new line characters. All these characters are invisible, but the blank line suggests that the new line character is the part of this string. One can confirm the contents of this variable by taking its octal dump: $ echo “#IFS” | od -bc 0000000 040 011 012 012 \t \n \n 0000004The space character is represented by the ASCI octal value 040. \t and \n represent the tab and new line characters, respectively. You normally do not need to change this variable, but advanced shell programming sometimes need to make a temporary change to IFS.

PATH: PATH is a list of directories that the shell uses to locate executable files for commands. So if the PATH is set to: /bin:/usr/bin:/usr/local/bin:and Is is typed, the shell would look for /bin/Is, /usr/bin/Is etc. This allows to create a shell script or program and run it as a command from the current directory without having to explicitly say “./filename”.

LOGNAME: This variable shows the user name. It is used when in shell scripts which require to know just the user name before deciding what it should do.

PROMPT: PS1, the main shell prompt can be used to create user's own custom prompt. eg. $ export PS1=”(\h) \w ” ← (lumberjack) ~>The shell often incorporates efficient mechanisms for specifying common parts of the shell prompts.