Linux Interview
Linux Interview
2. Q. How do you list all files in a directory, including the hidden files?
A. ls -a (-a, do not hide entries starting with .)
3. Q. How do you find out all processes that are currently running?
A. ps -f (-f does full-format listing.)
4. Q. How do you find out the processes that are currently running or a
particular user?
A. ps -au Myname (-u by effective user ID (supports names)) (a - all
users)
8. Q. What would you use to view contents of a large error log file?
A. tail -10 file_name ( last 10 rows)
12.Q. How do you create a symbolic link to a file (give some reasons of
doing so)?
A. ln /../file1 Link_name
Links create pointers to the actual files, without duplicating the contents
of
the files. That is, a link is a way of providing another name to the same
file.
There are two types of links to a file:Hard link, Symbolic (or soft) link;
Q. in current directory
A. ls -ps (p- directory; s - size)
A. bg %4 (job 4)
18 Q. What utility would you use to replace a string '2001' for '2002' in a
text file?
19. Q. What utility would you use to cut off the first column in a text file?
A. awk, kde
27. Q. What command do you type to find help about the command who?
A. $ man who
28. Q. What is the difference between home directory and working directory?
A. Home directory is the directory you begin at when you log into the
system. Working directory can be anywhere on the system and it is where you
are currently
working.
29. Q. Which directory is closer to the top of the file system tree, parent
directory or current directory?
A. The parent directory is above the current directory, so it is closer
to
the root or top of the
file system.
32. Q. What are two subtle differences in using the more and the pg commands?
A. With the more command you display another screenful by pressing
the spacebar, with pg you press the return key.
The more command returns you automatically to the UNIX
shell when completed, while pg waits until you press return.
33. Q. When is it better to use the more command rather than cat command?
A. It is sometimes better to use the more command when you are viewing
a file that will display over one screen.
34. Q. What are two functions the move mv command can carry out?
A. The mv command moves files and can also be used to rename a file or
directory.
36. The soccer league consists of boy and girl teams. The boy file names
begin
with B, the girl teams begin with G. All of these files are in one directory
called "soccer", which is your current directory:
Bteam.abc Bteam.OOl Bteam.OO2 Bteam.OO4
Gteam.win Gteam.OOl Gteam.OO2 Gteam.OO3
Write the commands to do the following:
a) rename the file Bteam.abc to Bteam.OO3.
b) erase the file Gteam. win after you have viewed the contents of the file
c) make a directory for the boy team files called "boys", and one for the
girl team files
called" girls"
d) move all the boy teams into the "boys" directory
e) move all the girl teams into the "girls" directory
f) make a new file called Gteam.OO4 that is identical to Gteam.OOl
g) make a new file called Gteam.OO5 that is identical to Bteam.OO2
A.
a) mv Bteam.abc Bteam.OO3.
b) cat Gteam.win -or- more Gteam.win
rm Gteam. win
c) mkdir boys
mkdir girls
d) mv Bteam* boys
e) mv Gteam* girls
f) cd girls
cp Gteam.OO1 Gteam.OO4
g) There are several ways to do this. Remember that we are currently in the
directory
/soccer/girls.
cp ../boys/Bteam.OO2 Gteam.OO5
or
cd ../boys
cp Bteam.OO2 ../girls/Gteam.OO5
37. Q. Draw a picture of the final directory structure for the "soccer"
directory, showing all the files and directories.
40. Q. Which of the quoting or escape characters allows the dollar sign ($)
to retain its special meaning?
A. The double quote (") allows the dollar sign ($) to retain its special
meaning.
Both the backslash (\) and single quote (') would remove the special meaning
of the dollar sign.
47. Q. How can you find a path to the file in the system?
A. locate file_name (locate - list files in databases that match a
pattern)
53. Q. If you would like to run two commands in sequence what operators you
can use?
60. Q. What is the best way to see the end of a logfile.log file?
A. Use tail command - output the last part of files
tail -n file_name ( the last N lines, instead of the last 10 as default)
61. Q. Please write a loop for removing all files in the current directory
that contains a word 'log'
A. for i in *log*; do rm $i; done
^Back to Top
Unix/Linux administration interview questions
What is LILO?
LILO stands for Linux boot loader. It will load the MBR, master boot record,
into the memory, and tell the system which partition and hard drive to boot
from.
What is the main advantage of creating links to a file instead of copies of
the file?
A: The main advantage is not really that it saves disk space (though it does
that too) but, rather, that a change of permissions on the file is applied
to all the link access points. The link will show permissions of lrwxrwxrwx
but that is for the link itself and not the access to the file to which the
link points. Thus if you want to change the permissions for a command, such
as su, you only have to do it on the original. With copies you have to find
all of the copies and change permission on each of the copies.
Write a command to find all of the files which have been accessed within the
last 30 days.
find / -type f -atime -30 > December.files
This command will find all the files under root, which is ¡®/¡‾, with file
type is file. ¡®-atime -30¡ä will give all the files accessed less than 30
days ago. And the output will put into a file call December.files.
What is the most graceful way to get to run level single user mode?
A: The most graceful way is to use the command init s.
If you want to shut everything down before going to single user mode then do
init 0 first and from the ok prompt do a boot -s.
What does the following command line produce? Explain each aspect of this
line.
$ (date ; ps -ef | awk ¡®{print $1}¡‾ | sort | uniq | wc -l ) >> Activity.
log
A: First let¡‾s dissect the line: The date gives the date and time as the
first command of the line, this is followed by the a list of all running
processes in long form with UIDs listed first, this is the ps -ef. These are
fed into the awk which filters out all but the UIDs; these UIDs are piped
into sort for no discernible reason and then onto uniq (now we see the
reason for the sort - uniq only works on sorted data - if the list is A, B,
A, then A, B, A will be the output of uniq, but if it¡‾s A, A, B then A, B
is the output) which produces only one copy of each UID.
These UIDs are fed into wc -l which counts the lines - in this case the
number of distinct UIDs running processes on the system. Finally the results
of these two commands, the date and the wc -l, are appended to the file "
Activity.log". Now to answer the question as to what this command line
produces. This writes the date and time into the file Activity.log together
with the number of distinct users who have processes running on the system
at that time. If the file already exists, then these items are appended to
the file, otherwise the file is created.
1. How do you list the files in an UNIX directory while also showing
hidden files? ls -ltra
2. How do you execute a UNIX command in the background? Use the ¡°&¡±.
3. What UNIX command will control the default file permissions when files
are created? umask
4. Explain the read, write, and execute permissions on a UNIX directory.
Read allows you to see and list the directory contents. Write allows you to
create, edit and delete files and subdirectories in the directory. Execute
gives you the permissions to run programs or shells from the directory.
5. What is the difference between a soft link and a hard link? A symbolic
(soft) linked file and the targeted file can be located on the same or
different file system while for a hard link they must be located on the same
file system.
6. Give the command to display space usage on the UNIX file system. df -
lk
7. Explain iostat, vmstat and netstat. iostat reports on terminal, disk
and tape I/O activity. vmstat reports on virtual memory statistics for
processes, disk, tape and CPU activity. netstat reports on the contents of
network data structures.
8. How would you change all occurrences of a value using VI? %s/(old
value)/(new value)/g
9. Give two UNIX kernel parameters that effect an Oracle install. SHMMAX
& SHMMNI
10. Briefly, how do you install Oracle software on UNIX? Basically, set up
disks, kernel parameters, and run orainst.
C++ Interview Questions
C++ code examples for job interviews
Q: Write a short code using C++ to print out all odd number from 1 to 100
using a for loop(Asked by Intacct.com people)
for( unsigned int i = 1; i < = 100; i++ )
if( i & 0x00000001 )
cout << i<<",";
ISO layers and what layer is the IP operated from?( Asked by Cisco system
people)
cation, Presentation, Session, Transport, Network, Data link and Physical.
The IP is operated in the Network layer.
3.Q: Write a program that ask for user input from 5 to 9 then calculate the
average( Asked by Cisco system people)
A.int main()
{
int MAX=4;
int total =0;
int average=0;
int numb;
cout<<"Please enter your input from 5 to 9";
cin>>numb;
if((numb <5)&&(numb>9))
cout<<"please re type your input";
else
for(i=0;i<=MAX; i++)
{
total = total + numb;
average= total /MAX;
}
cout<<"The average number is"<<average<<endl;
return 0;
}
4.Q: Can you be bale to identify between Straight- through and Cross- over
cable wiring? and in what case do you use Straight- through and Cross-over?
(Asked by Cisco system people)
A. Straight-through is type of wiring that is one to to one connection Cross
- over is type of wiring which those wires are got switched
We use Straight-through cable when we connect between NIC Adapter and Hub.
Using Cross-over cable when connect between two NIC Adapters or sometime
between two hubs.
5.Q: If you hear the CPU fan is running and the monitor power is still on,
but you did not see any thing show up in the monitor screen. What would you
do to find out what is going wrong? (Asked by WNI people)
A. I would use the ping command to check whether the machine is still alive(
connect to the network) or it is dead.
^Back to Top
C++ object-oriented interview questions
1. How do you write a function that can reverse a linked-list? (Cisco System)
void reverselist(void)
{
if(head==0)
return;
if(head->next==0)
return;
if(head->next==tail)
{
head->next = 0;
tail->next = head;
}
else
{
node* pre = head;
node* cur = head->next;
node* curnext = cur->next;
head->next = 0;
cur->next = head;
for(; curnext!=0; )
{
cur->next = pre;
pre = cur;
cur = curnext;
curnext = curnext->next;
}
curnext->next = cur;
}
}
2. What is polymorphism?
Polymorphism is the idea that a base class can be inherited by several
classes. A base class pointer can point to its child class and a base class
array can store different child class objects.
3. How do you find out if a linked-list has an end? (i.e. the list is not a
cycle)
You can find out by using 2 pointers. One of them goes 2 nodes each time.
The second one goes at 1 nodes each time. If there is a cycle, the one that
goes 2 nodes each time will eventually meet the one that goes slower. If
that is the case, then you will know the linked-list is a cycle.
4. How can you tell what shell you are running on UNIX system?
You can do the Echo $RANDOM. It will return a undefined variable if you are
from the C-Shell, just a return prompt if you are from the Bourne shell, and
a 5 digit random numbers if you are from the Korn shell. You could also do
a ps -l and look for the shell with the highest PID.
5. What is Boyce Codd Normal form?
A relation schema R is in BCNF with respect to a set F of functional
dependencies if for all functional dependencies in F+ of the form a->b,
where a and b is a subset of R, at least one of the following holds:
¡¤ a->b is a trivial functional dependency (b is a subset
of a)
¡¤ a is a superkey for schema R
^Back to Top
Interview questions on C/C++
A reader submitted the interview questions he was asked. More C/C++
questions will be added here, as people keep sending us a set of 2-3
questions they got on their job itnerview.
Q1: Tell how to check whether a linked list is circular.
A: Create two pointers, each set to the start of the list. Update each as
follows:
while (pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print ("circular\n");
}
}
Q2: OK, why does this work?
If a list is circular, at some point pointer2 will wrap around and be either
at the item just before pointer1, or the item before that. Either way, it¡‾
s either 1 or 2 jumps until they meet.
How can you quickly find the number of elements stored in a a) static array
b) dynamic array ?
Why is it difficult to store linked list in an array?
How can you find the nodes with repetetive data in a linked list?
Write a prog to accept a given string in any order and flash error if any of
the character is different. For example : If abc is the input then abc, bca
, cba, cab bac are acceptable but aac or bcd are unacceptable.
This is a C question that I had for an intern position at Microsoft: Write
out a function that prints out all the permutations of a string. For example
, abc would give you abc, acb, bac, bca, cab, cba. You can assume that all
the characters will be unique. After I wrote out my function, he asked me to
figure out from the code how many times the printf statement is run, and
also questions on optimizing my algorithm.
What¡‾s the output of the following program? Why?
#include <stdio.h>
main()
{
typedef union
{
int a;
char b[10];
float c;
}
Union;
Union x,y = {100};
x.a = 50;
strcpy(x.b,"hello");
x.c = 21.50;
printf("Union x : %d %s %f \n",x.a,x.b,x.c );
printf("Union y :%d %s%f \n",y.a,y.b,y.c);
}
Given inputs X, Y, Z and operations | and & (meaning bitwise OR and AND,
respectively)
What is output equal to in
output = (X & Y) | (X & Z) | (Y & Z)
^Back to Top
C++ gamedev interview questions
This set of questions came from a prominent gaming company. As you can see,
the answers are not given (the interviews are typically conducted by senior
developers), but there¡‾s a set of notes with common mistakes to avoid.
1. Explain which of the following declarations will compile
and what will be constant - a pointer or the value pointed at:
o const char *
o char const *
o char * const
Note: Ask the candidate whether the first declaration is pointing to a
string or a single character. Both explanations are correct, but if he says
that it¡‾s a single character pointer, ask why a whole string is initialized
as char* in C++. If he says this is a string declaration, ask him to
declare a pointer to a single character. Competent candidates should not
have problems pointing out why const char* can be both a character and a
string declaration, incompetent ones will come up with invalid reasons.
2. You¡‾re given a simple code for the class BankCustomer.
Write the following functions:
o Copy constructor
o = operator overload
o == operator overload
o + operator overload (customers¡‾
balances should be added up, as an example of joint account between husband
and wife)
Note:Anyone confusing assignment and equality operators should be dismissed
from the interview. The applicant might make a mistake of passing by value,
not by reference. The candidate might also want to return a pointer, not a
new object, from the addition operator. Slightly hint that you¡‾d like the
value to be changed outside the function, too, in the first case. Ask him
whether the statement customer3 = customer1 + customer2 would work in the
second case.
3. What problems might the following macro bring to the
application?
#define sq(x) x*x
4. Consider the following struct declarations:
5. struct A { A(){ cout << "A"; } };
6. struct B { B(){ cout << "B"; } };
7. struct C { C(){ cout << "C"; } };
8. struct D { D(){ cout << "D"; } };
9. struct E : D { E(){ cout << "E"; } };
10. struct F : A, B
11. {
12. C c;
13. D d;
14. E e;
15. F() : B(), A(),d(),c(),e() { cout << "F"; }
};
What constructors will be called when an instance of F is initialized?
Produce the program output when this happens.
16. Anything wrong with this code?
17. T *p = new T[10];
18. delete p;
No. There is nothing you can do in C++ that you cannot do in C. After all
you can write a C++ compiler in C
~Sample()
{
delete ptr;
}
void PrintVal()
{
cout << ¡°The value is ¡± << *ptr;
}
};
void SomeFunc(Sample x)
{
cout << ¡°Say i am in someFunc ¡± << endl;
}
int main()
{
Sample s1 = 10;
SomeFunc(s1);
s1.PrintVal();
}