Unix Interview Questions and Answers
Question - 81 : - Explain links and symbolic links.
Answer - 81 : -
Links are defined as a second name which is used to assign more than one name to a file. Although links are referred to as a pointer to another file it cannot be used to link filenames on different computers.
A Symbolic link is also known as the soft link. It is defined as a special type of file that contains links or references to another file or directory in the form of an absolute or relative path. It does not contain the data actually in the target file but the pointer to another entry in the file system. Symbolic links can also be used to create a file system.
The following command is used to create a symbolic link:
- Ln –s target link_name
- Here, the path is ‘target’
- The name of the link is represented by link_name.
Question - 82 : - Explain the alias mechanism.
Answer - 82 : -
To avoid typing long commands or to improve efficiency, the alias command is used to assign another name to a command. Basically, it acts as a shortcut to the larger commands which can be typed and run instead.
For creating an alias in Unix, following command format is used:
alias name=’command you want to run’
Here, replace the ‘name’ with your shortcut command and replace ‘command you want to run’ with the larger command of which you want to create an alias of.
For Example, alias dir ‘Is –sFC’
Here, in the above example, ‘dir’ is another name for the command ‘Is-sFC’. Thus user now simply is required to remember and use the specified alias name and the command will perform the same task as to be performed by the long command.
Question - 83 : - What do you know about wildcard interpretation?
Answer - 83 : -
Wildcard characters are some special kind of characters that represent one or more other characters. Wildcard interpretation comes into the picture when a command-line contains these characters. In this case, when the pattern matches the input command, these characters are replaced by a sorted list of files.
Asterisk(*) and Question mark(?) are usually used as wildcard characters to set up a list of files while processing.
Question - 84 : - What do you understand by terms ‘system calls’ and ‘library functions’ with respect to UNIX command?
Answer - 84 : -
System calls: As the name implies, system calls are defined as an interface that is basically used in the kernel itself. Although, they may not be fully portable but these calls request the operating system to perform tasks on behalf of user programs.
The system calls appear as a normal C function. Whenever a system call is invoked within the operating system, the application program performs context switch from user space to kernel space.
Library functions: The set of common functions that are not part of the kernel but is used by the application programs are known as ‘Library functions’. As compared to system calls, library functions are portable and can perform certain tasks only in ‘kernel mode’. Also, it takes lesser time for execution as compared to the execution of system calls.
Question - 85 : - Explain pid.
Answer - 85 : - A pid is used to denote a unique process id. It basically identifies all the processes that run on the Unix system. It does not matter whether the processes are running in the frontend or in the backend.
Question - 86 : - What are the possible return values of kill() system call?
Answer - 86 : - Kill() system call is used to send signals to any processes.
This method returns the following return values:
Returns 0: It implies that the process exists with the given pid and the system allows sending signals to it.
Return -1 and errno==ESRCH: It implies that there is no existence of the process with specified pid. There may also exist some security reasons which is denying the existence of the pid.
Return -1 and errno==EPERM: It implies that there is no permit available for the process to be killed. The error also detects whether the process is present or not.
EINVAl: it implies an invalid signal.
Question - 87 : - Enlist the various commands that are used to know about the user information in UNIX.
Answer - 87 : -
The various commands that are used for displaying the user information in Unix are enlisted below:
- Id: displays the active user id with login and group.
- Last: displays the last login of the user in the system.
- Who: determines who is logged onto the system.
- groupadd admin: this command is used to add group ‘admin’.
- usermod –a: user to add an existing user to the group.
Question - 88 : - What do you know about tee command and its usage?
Answer - 88 : -
‘tee’ command is basically used in connection with pipes and filters.
This command basically performs two tasks:
- Get data from standard input and send it to the standard output.
- Redirects a copy of the input data to the specified file.
Question - 89 : - Explain mount and unmount command.
Answer - 89 : -
Mount command: As the name suggests, the mount command mounts a storage device or file system onto an existing directory and thus making it accessible to users.
Unmount command: This command unmounts the mounted file system by safely detaching it. It also the task of this command to inform the system to complete any pending read and write operations.
Question - 90 : - What is the “chmod” command?
Answer - 90 : -
Chmod command is used to change file or directory access permission and is the most frequently used command in Unix. According to mode, the chmod command changes the permission of each given file.
The syntax of the chmod command is:
Chmod [options] mode filename.
Here in the above format, options could be:
- -R: recursively change the permission of the file or directory.
- -v: verbose, i.e. output a diagnostic for every file processed.
- -c: report only when the change is made.
- Etc.