Friday, April 15, 2011

UNIX Commands Interview Questions Part 4


1. How to switch to a super user status to gain privileges?
Use 'su' command. The system asks for password and when valid entry is made the user gains super user (admin) privileges.

2. What are shell variables?
Shell variables are special variables, a name-value pair created and maintained by the shell.
Example: PATH, HOME, MAIL and TERM

3. What is redirection?
Directing the flow of data to the file or from the file for input or output.
Example : ls > wc

4. How to terminate a process which is running and the specialty 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 except the login shell.

5. What is a pipe and give an example?
A pipe is two or more commands separated by pipe char '|'. That tells the shell to arrange for the output of the preceding command to be passed as input to the following command.
Example : ls -l | pr
The output for a command ls is the standard input of pr.
When a sequence of commands are combined using pipe, then it is called pipeline.

6. 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 is system-dependent whether the process could be a zombie.
'kill()' returns -1, 'errno == ESRCH' either no process exists with the given PID, or security enhancements are causing the system to deny its existence. (On some systems, the process could be a zombie.)
'kill()' returns -1, 'errno == EPERM' the system would not allow you to kill the specified process. This means that either the process exists (again, it could be a zombie) or draconian security enhancements are present
(e.g. your process is not allowed to send signals to *anybody*).
'kill()' returns -1, with some other value of 'errno' you are in trouble! The most-used technique is to assume that success or failure with 'EPERM' implies that the process exists, and any other error implies that it doesn't.
An alternative exists, if you are writing specifically for a system (or all those systems) that provide a '/proc'
filesystem: checking for the existence of '/proc/PID' may work.

7. What is relative path and absolute path.
Absolute path: Exact path from root directory.
Relative path: Relative to the current path.

1 comment:


  1. Hi There,

    That’s how speedy and easy this read was! Looking forward to more of such powerful content on UNIX Commands Interview Questions !

    Though the basic Unix-like systems unit of a Unix and include at least some BSD code, and some systems also include GNU utilities in their distributions. I've came across forums it says you can create your own mini OS using C/C++ compiler.
    Is that entirely true? How much time it takes to replicate an OS like Chrome OS

    Excellent tutorials - very easy to understand with all the details. I hope you will continue to provide more such tutorials.

    Shukran,
    Preethi

    ReplyDelete