Monday, December 20, 2010

UNIX Commands Interview Questions

UNIX Commands Interview Questions

1.What is Event-Based Scheduling?

When you use event-based scheduling, the Informatica Server starts a session when it locates the specified indicator file. To use event-based scheduling, you need a shell command, script, or batch file to create an indicator file when all sources are available. The file must be created or sent to a directory local to the Informatica Server. The file can be of any format recognized by the Informatica Server operating system. The Informatica Server deletes the indicator file once the session starts.
Use the following syntax to ping the Informatica Server on a UNIX system:
pmcmd ping [{user_name | %user_env_var} {password | %password_env_var}] [hostname:]portno
Use the following syntax to start a session or batch on a UNIX system:
pmcmd start {user_name | %user_env_var} {password | %password_env_var} [hostname:]portno [folder_name:]{session_name | batch_name} [:pf=param_file] session_flag wait_flag
Use the following syntax to stop a session or batch on a UNIX system:
pmcmd stop {user_name | %user_env_var} {password | %password_env_var} [hostname:]portno[folder_name:]{session_name | batch_name} session_flag
Use the following syntax to stop the Informatica Server on a UNIX system:
pmcmd stopserver {user_name | %user_env_var} {password | %password_env_var} [hostname:]portno

2. Explain the following commands.
$ ls > file1
$ banner hi-fi > message
$ cat par.3 par.4 par.5 >> report
$ cat file1>file1
$ date ; who
$ date ; who > logfile
$ (date ; who) > logfile

3.wht is the significance of "tee" cmd? 

It reads the standard input and sends it to the standard output while redirecting a copy of what it has read to
the file specified by the user.

4. What does the command “ $who | sort –logfile > newfile” do?

The input from a pipe can be combined with the input from a file . The trick is to use the special symbol “-“
(a hyphen) for those commands that recognize the hyphen as std input.
In the above command the output from who becomes the std input to sort , meanwhile sort opens the file
logfile, the contents of this file is sorted together with the output of who (rep by the hyphen) and the sorted
output is redirected to the file newfile.

5. What does the command “$ls | wc –l > file1” do?

ls becomes the input to wc which counts the number of lines it receives as input and instead of displaying
this count , the value is stored in file1.

6. Which of the following commands is not a filter man , (b) cat , (c) pg , (d) head

Ans: man
A filter is a program which can receive a flow of data from std input, process (or filter) it and send the result
to the std output.

7. How is the command “$cat file2 “ different from “$cat >file2 and >> redirection operators ?

is the output redirection operator when used it overwrites while >> operator appends into the file.

9. Explain the steps that a shell follows while processing a command.

After the command line is terminated by the key, the shel goes ahead with processing the command line in
one or more passes. The sequence is well defined and assumes the following order.

Parsing
quoted. All consecutive occurrences of a space or tab are replaced here with a single space.

: The shell first breaks up the command line into words, using spaces and the delimiters, unless

Variable evaluation : Any command surrounded by backquotes is executed by the shell which then: The shell finally scans the command line for wild-cards (the characters *, ?, [, ]).
Command substitution:Any command surrounded by backquotes is executed by the shell which then 
replaces the standard output of the command into the command line.
Wild-card interpretation:Any word containing a wild-card is replaced by a sorted list of
filenames that match the pattern. The list of these filenames then forms the arguments to the command.
PATH evaluation: It finally looks for the PATH variable to determine the sequence of directories it has to search in order to hunt for the command.
 
12. What is the difference between cat and more command?

Cat displays file contents. If the file is large the contents scroll off the screen before we view it. So
command 'more' is like a pager which displays the contents page by page.
13. Write a command to kill the last background job?


Kill $!
14. Which command is used to delete all files in the current directory and all its sub-directorories?


rm -r *

15. Write a command to display a file’s contents in various formats?

$od -cbd file_name
c - character, b - binary (octal), d-decimal, od=Octal Dump.

16. What will the following command do?

$ echo *
It is similar to 'ls' command and displays all the files in the current directory.

17. Is it possible to create new a file system in UNIX?

Yes, ‘mkfs’ is used to create a new file system.

18. Is it possible to restrict incoming message?

Yes, using the ‘mesg’ command.

19. What is the use of the command "ls -x chapter[1-5]"

ls stands for list; so it displays the list of the files that starts with 'chapter' with suffix '1' to '5', chapter1,
chapter2, and so on.

20. Is ‘du’ a command? If so, what is its use?

Yes, it stands for ‘disk usage’. With the help of this command you can find the disk capacity and free space
of the disk.

21. Is it possible to count number char, line in a file; if so, How?

Yes, wc-stands for word count.
wc -c for counting number of characters in a file.
wc -l for counting lines in a file.



22. Name the data structure used to maintain file identification?

‘inode’, each file has a separate inode and a unique inode number.

23. How many prompts are available in a UNIX system?

Two prompts, PS1 (Primary Prompt), PS2 (Secondary Prompt).
24. How does the kernel differentiate device files and ordinary files?


Kernel checks 'type' field in the file's inode structure.

25. 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.

26. 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

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

28. 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.

29. 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.

30. 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.

31. What is relative path and absolute path.

Absolute path : Exact path from root directory.
Relative path : Relative to the current path.

32.Construct pipes to execute the following jobs.
 
1. Output of who should be displayed on the screen with value of total number of users who have logged in
displayed at the bottom of the list.
2. Output of ls should be displayed on the screen and from this output the lines containing the word ‘poem’
should be counted and the count should be stored in a file.
3. Contents of file1 and file2 should be displayed on the screen and this output should be appended in a file
.
From output of ls the lines containing ‘poem’ should be displayed on the screen along with the count.
4. Name of cities should be accepted from the keyboard . This list should be combined with the list present
in a file. This combined list should be sorted and the sorted list
should be stored in a file ‘newcity’.
5. All files present in a directory dir1 should be deleted any error while deleting should be stored in a file
‘errorlog’.
11. What is the use of ‘grep’ command?

‘grep’ is a pattern search command. It searches for the pattern, specified in the command line with
appropriate option, in a file(s).
Syntax : grep
Example : grep 99mx mcafile


10. What difference between cmp and diff commands?
cmp - Compares two files byte by byte and displays the first mismatch
diff - tells the changes to be made to make the files identical
 

Friday, December 17, 2010

Simple Sql QAs


SQL 

Q1.  What is the basic difference between a join and a union? 

A1.  A join selects columns from 2 or more tables. A union selects rows.  

Q2.  What is normalization and what are the five normal forms? 

A2.  Normalization is a design procedure for representing data in tabular format.  The five normal forms are progressive rules to represent the data with minimal redundancy. 

Q3.  What are foreign keys? 

A3.  These are attributes of one table that have matching values in a primary key in another table, allowing for relationships between tables. 

Q4.  Describe the elements of the SELECT query syntax. 
A4.  SELECT element FROM table WHERE conditional statement. 

Q5.  Explain the use of the WHERE clause. 
A5.  WHERE is used with a relational statement to isolate the object element or row. 

Q6.  What techniques are used to retrieve data from more than one table in a single SQL statement? 
A6.  Joins, unions and nested selects are used to retrieve data. 

Q7.  What is a view? Why use it? 
A7.  A view is a virtual table made up of data from base tables and other views, but not stored separately. 

Q8.  Explain an outer join. 
A8.   An outer join includes rows from tables when there are no matching values in the tables. 

Q9.  What is subselect?  Is it different from a nested select? 
A9.  Subselect is a select which works in conjunction with another select. A nested select is a kind of subselect where the inner select passes to the where criteria for the outer select.

Q10.  What is the difference between group by and order by? 
A10.  Group by controls the presentation of the rows, order by controls the presentation of the columns for the results of the SELECT statement. 

Q11.  What keyword does an SQL SELECT statement use for a string search? 
A11.  The LIKE keyword allows for string searches.  The % sign is used as a wildcard. 

Q12.  What are some sql aggregates and other built-in functions? 
A12.  The common aggregate, built-in functions are AVG, SUM, MIN, MAX, COUNT and DISTINCT. 

Q13.  How is the SUBSTR keyword used in sql? 
A13.  SUBSTR is used for string manipulation with column name, first position and string length used as arguments.  Eg. SUBSTR (NAME, 1 3) refers to the first three characters in the column NAME. 

Q14.   Explain the EXPLAIN statement. 
A14.  The explain statement provides information about the optimizer's choice of access path of the sql. 

Q15.  What is referential integrity? 
A15.  Referential integrity refers to the consistency that must be maintained between primary and foreign keys, ie every foreign key value must have a corresponding primary key value. 

Q16.  What is a NULL value?  What are the pros and cons of using NULLS? 
A16.  A NULL value takes up one byte of storage and indicates that a value is not present as opposed to a space or zero value.  It's the DB2 equivalent of TBD on an organizational chart and often correctly portrays a business situation.  Unfortunately, it requires extra coding for an application program to handle this situation. 

Q17.  What is a synonym?  How is it used? 
A17.  A synonym is used to reference a table or view by another name.  The other name can then be written in the application code pointing to test tables in the development stage and to production entities when the code is migrated.  The synonym is linked to the AUTHID that created it. 

Q18.  What is an alias and how does it differ from a synonym? 
A18.  An alias is an alternative to a synonym, designed for a distributed environment to avoid having to use the location qualifier of a table or view.  The alias is not dropped when the table is dropped. 

Q19. When can an insert of a new primary key value threaten referential integrity? 
A19.  Never. New primary key values are not a problem.  However, the values of foreign key inserts must have corresponding primary key values in their related tables. And updates of primary key values may require changes in foreign key values to maintain referential integrity. 

Q20.  What is the difference between static and dynamic sql? 
A20.  Static sql is hard-coded in a program when the programmer knows the statements to be executed.  For dynamic sql the program must dynamically allocate memory to receive the query results. 

Q21.  Compare a subselect to a join.
 
A21. Any subselect can be rewritten as a join, but not vice versa.  Joins are usually more efficient as join rows can be returned immediately, subselects require a temporary work area for inner selects results while processing the outer select. 

Q22.  What is the difference between IN subselects and EXISTS subselect? 
A22.  If there is an index on the attributes tested an IN is more efficient since DB2 uses the index for the IN.  (IN for index is the mnemonic). 

Q23.  What is a Cartesian product? 
A23. A Cartesian product results from a faulty query.  It is a row in the results for every combination in the join tables. 

Q24.  What is a tuple? 
A24.  A tuple is an instance of data within a relational database. 

Q25.  What is the difference between static and dynamic sql? 
A25.  Static sql is compiled and optimized prior to its execution; dynamic is compiled and optimized during execution. 

Q26.  Any SQL implementation covers data types in couple of main categories. Which of the following are those data types ? (Check all that apply) A. NUMERIC   B. CHARACTER   C. DATE AND TIME   D. BLOBS   E. BIT 

A26. A,B,C. Not all SQL implementations have a BLOB or a BIT data types. 

Q27.  We have a table with a CHARACTER data type field. We apply a ">" row comparison between this field and another CHARACTER field in another table. What will be the results for records with field value of NULL ? (Check one that applies the best)  A. TRUE   B. FALSE   C. UNKNOWN   D. Error.   E. Those records will be ignored 

A27.   C. NULL in a row when compared will give an UNKNOWN result. 

Q28.  Any database needs to go through a normalization process to make sure that data is represented only once. This will eliminate problems with creating or destroying data in the database. The normalization process is done usually in three steps which results in first, second and third normal forms. Which best describes the process to obtain the third normal form? (Check one that applies the best)  A. Each table should have related columns.   B. Each separate table should have a primary key.   C. We have a table with multi-valued key. All columns that are dependent on only one or on some of the keys should be moved in a different table.  D. If a table has columns not dependent on the primary keys, they need to be moved in a separate table.   E. Primary key is always UNIQUE and NOT NULL. 

A28.  D. All columns in a table should be dependent on the primary key. This will eliminate transitive dependencies in which A depends on B, and B depends on C, but we're not sure how C depends on A. 

Q29.  SQL can be embedded in a host program that uses a relational database as a persistent data repository. Some of the most important pre-defined structures for this mechanism are SQLDA ("SQL Descriptor Area") and SQLCA ("SQL Communications Area") SQLCA contains two structures - SQLCODE and SQLSTATE. SQLSTATE is a standard set of error messages and warnings in which the first two characters defines the class and the last three defines the subclass of the error. Which of the following SQLSTATE codes is interpreted as "No data returned"? (Check one that applies the best) A. 00xxx   B. 01xxx  C. 02xxx   D. 22xxx   E. 2Axxx 

A29. C. 00 - is successful completion, 01 - warnings, 22 - is data exception and 2A is syntax error. The SQLSTATE code format returned for "No data returned" is "02xxx".

Informatica interview questions & FAQs ?

What is a source qualifier?
What is a surrogate key?
What is difference between Mapplet and reusable transformation?
What is DTM session?
What is a Mapplet?
What is a look up function? What is default transformation for the look up function?
What is difference between a connected look up and unconnected look up?
What is up date strategy and what are the options for update strategy?
What is subject area?
What is the difference between truncate and delete statements?
What kind of Update strategies are normally used (Type 1, 2 & 3) & what are the differences?
What is the exact syntax of an update strategy?
What are bitmap indexes and how and why are they used?
What is bulk bind? How does it improve performance?
What are the different ways to filter rows using Informatica transformations?
What is referential Integrity error? How do you rectify it?
What is DTM process?
What is target load order?
What exactly is a shortcut and how do you use it?
What is a shared folder?
What are the different transformations where you can use a SQL override?
What is the difference between a Bulk and Normal mode and where exactly is it defined?
What is the difference between Local & Global repository?
What are data driven sessions?
What are the common errors while running a Informatica session?
What are worklets and what is their use?
What is change data capture?
What exactly is tracing level?
What is the difference between constraints based load ordering and target load plan?
What is a deployment group and what is its use?
When and how a partition is defined using Informatica?
How do you improve performance in an Update strategy?
How do you validate all the mappings in the repository at once?
How can you join two or more tables without using the source qualifier override SQL or a Joiner transformation?
How can you define a transformation? What are different types of transformations in Informatica?
How many repositories can be created in Informatica?
How many minimum groups can be defined in a Router transformation?
How do you define partitions in Informatica?
How can you improve performance in an Aggregator transformation?
How does the Informatica know that the input is sorted?    
How many worklets can be defined within a workflow?
How do you define a parameter file? Give an example of its use.
If you join two or more tables and then pull out about two columns from each table into the source qualifier and then just pull out one column from the source qualifier into  an Expression transformation and then do a ‘generate SQL’ in the source qualifier how many columns will show up in the generated SQL.
In a Type 1 mapping with one source and one target table what is the minimum number of update strategy transformations to be used?
At what levels can you define parameter files and what is the order?
In a session log file where can you find the reader and the writer details?
For joining three heterogeneous tables how many joiner transformations are required?
Can you look up a flat file using Informatica?
While running a session what default files are created?
Describe the use of Materialized views and how are they different from a normal view.