DronaBlog

Monday, December 17, 2018

Unix Interview Questions and Answers - Part I


Are you preparing for Unix interview? Unix is major operating systems on which enterprise applications run. Because of it, the interviewer asks Unix related questions during interviews of technologies such as Java, Hadoop, and Python etc. Are you planning to give an interview for support project for which Unix knowledge is required? If yes, then refer to this article as it provides detailed questions and answers about Unix.

Q 1: What is the process in Unix and What are the types of process exists in Unix?

Answer
A process is an instance of a program running in an Operating System. Normally, the process is started when a program is initiated.

Type of Processes: There are two types of the process
a) Foreground Processes
b) Background Processes


Q 2: What is the command to list the directories and the files?

Answer:
This is a very basic question asked during an interview to understand whether the candidate has basic knowledge of Unix.

The command below is used to list the directories and the files in current location -
$ ls -ltr

ls : To list files
ls -l : To list files with additional information

Every file line begins with d, -, or l. These characters indicate the type of the file which is shown on the screen as result.

e.g
drwrrwxr-x 3 abc abc 16   Jan 10 2018 temp_dir
-rw-rw-r-- 2 abc abc 4028 Mar 5  17:12 test.sh

Learn more: Click here to learn more about ls command.

Q 3: What are the differences between the Zombie and Orphan processes?

Answer: The differences between the Zombie and the Orphan processes are listed as below -

Zombie Process
Orphan Process
Zombie processes are those processes which are killed or completed execution but still show an entry in the process table.
A child process which remains running itself even after its parent process is completed or terminated is called as an orphan process.
Zombies only occupy space in the process table
Orphan Process uses memory resources
If the Zombies that exist for more time, then it indicates an issue in the parent program
The orphan process is get created unknowingly and unintentionally due to process crash
The zombie process shows the process with a Z state
The orphan processes are terminated


ReadClick here, to know more details about the Zombie, Orphan and the Daemon processes.


Q 4: How to run the process in background and foreground?

Answer: Follow the below steps to run a process in
A. Background:
To run any process in the background, we need to '&' sign at the end of the command. By using '&' sign we are telling Unix system that runs the given process in the background so that we can continue to use the command prompt. 

The example of running the process as the background process is as -

sh run_calculate_interest.sh &

B. Foreground:
If any process is running background and you would like to bring it to foreground then use the steps below -
a)  Get job id of the process
$ jobs

The output will look like as 
[1]   7095 Running                 run_calculate_interest&
[2]   7206 Running                 run_app &

b) Use jobid and run it in the foreground as
$ fg 7095

Learn more: Unix tutorial 




Q 5: Assume that one of the processes is running more than 24 hrs. How you are going to identify such process and remove or kill it?

Answer: Sometimes, interviewer tries to create the complex scenario for the simple answer. So do not get confused with the description of the question. The underline principle will remain the same to kill the process. By asking this question, an interviewer is trying to check whether how extensive you worked on Unix system.

To identify long running processes we can use commands such as 'Top' or 'jobs'. However, you can also us 'ps -ef'  command to know running process.

The above command will provide the process ids (or Job ids) for running processes.

Use below command to kill the process-
$ kill -9 PID

Here, PID is process id.









No comments:

Post a Comment

Please do not enter any spam link in the comment box.

Dynatrace : An Overview

  Dynatrace, a leading provider of software intelligence, offers a powerful platform designed to monitor, analyze, and optimize the performa...