Best Unix Interview Questions Part – 3
1.How can you get/set an environment variable from a program?
Getting the value of an environment variable is done by using `getenv()’.Setting the value of an environment variable is done by using `putenv()’.
2.How can a parent and child process communicate?
A parent and child can communicate through any of the normal inter-process communication schemes (pipes,sockets,message queues,shared memory),but also have some special ways to communicate that take advantage of their relationship as a parent and child.One of the most obvious is that the parent can get the exit status of the child.
3.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 may need to check the child’s exit status.To be able to get this information,the parent calls `wait()’;
In the interval between the child terminating and the parent calling `wait()’,the child is said to be a `zombie’ (If you do `ps’,the child will have a `Z’ in its status field to indicate this.)
4.What are the process states in Unix?
As a process executes it changes state according to its circumstances.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 a signal.
Zombie :
The process is dead but have not been removed from the process table.
5.What is an advantage of executing a process in background?
The most common reason to put a process in the background is to allow you to do something else interactively without waiting for the process to complete.At the end of the command you add the special background symbol,.This symbol tells your shell to execute the given command in the background.
Example:
cp
*.
* ../backup (cp is for copy)
6.How would you kill a process?
The kill command takes the PID as one argument; this identifies which process to terminate.The PID of a process can be got using ‘ps’ command.
7.What is ‘ps’ command for?
The ps command prints the process status for some or all of the running processes.The information given are the process identification number (PID),the amount of time that the process has taken to execute so far etc.
8.What is a Daemon?
A daemon is a process that detaches itself from the terminal and runs,disconnected,in the background,waiting for requests and responding to them.It can also be defined as the background process that does not belong to a terminal session.
Many system functions are commonly performed by daemons,including the sendmail daemon,which handles mail,and the NNTP daemon,which handles USENET news.Many other daemons may exist.Some of the most common daemons are:
init: Takes over the basic running of the system when the kernel has finished the boot process.
inetd:
Responsible for starting network services that do not have their own stand-alone daemons.For example,inetd usually takes care of incoming rlogin,telnet,and ftp connections.
cron:
Responsible for running repetitive tasks on a regular schedule.
9.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 used to assign more than one name to a file,but cannot be used to assign 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 on the symbolic link is directed to the file pointed by the it.Both the limitations of links are eliminated in symbolic links.
Commands for linking files are:
Link ln filename1 filename2
Symbolic link ln -s filename1 filename2
10.Write a command to find the length of a line in a file?
The below command can be used to get a line from a file.sed -n ‘ p’ filename
11.How do you check how much space left in current drive?
By using “df” command in UNIX.For example “df -h .” will list how full your current drive is.This is part of anyone day to day activity so I think this Unix Interview question will be to check anyone who claims to working in UNIX but not really working on it.
12.How do you find which process is taking how much CPU?
By using “top” command in UNIX,there could be multiple follow-up UNIX command interview questions based upon response of this because “TOP” command has various interactive options to sort result based upon various parameter.
13.How do you copy file from one host to other?
Many options but you can say by using “scp” command.You can also use rsync command to answer this UNIX interview question or even sftp would be ok.
14.How do you know if a remote host is alive or not?
You can check these by using either ping or telnet command in UNIX.This question is most asked in various Unix command Interview because its most basic networking test anybody wants to do it.
15.How will you run a process in background?How will you bring that into foreground and how will you kill that process?
For running a process in background use “” in command line.For bringing it back in foreground use command “fg jobid” and for getting job id you use command “jobs”,for killing that process find PID and use kill -9 PID command.This is indeed a good Unix Command interview questions because many of programmer not familiar with background process in UNIX.
16.How do you find how many cpu are in your system and there details?
By looking into file /etc/cpuinfo for example you can use below command:
cat /proc/cpuinfo
17.How do you check if a particular process is listening on a particular port on remote host?
By using telnet command for example “telnet hostname port”,if it able to successfully connect then some process is listening on that port.
18.How do you find whether your system is 32 bit or 64 bit?
Either by using “uname -a” command or by using “arch” command.
19.How do you find for how many days your Server is up?
By using uptime command in UNIX
20.Your application home directory is full? How will you find which directory is taking how much space?
By using disk usage (DU) command in Unix for example
du -sh .| grep G will list down all the directory which has GIGS in Size.