You are on page 1of 21

Platform Independent Team Interview Questions [ C language ] - Must have. - What is the mechanism behind a function call?

- Summary - Argument pushed on stack in reverse order, pointer of where to jump back to put on stack, local vars pushed on stack. - Detailed - Depends on the compiler and CPU architecture, but basically: the program pushes parameters on the stack, or places them in registers. The program then executes a CALL instruction, which contains the address of the function being called. The CPU pushes the return address and optionally some program state (registers) on the stack and jumps to the called address. When the function returns, it places the function's return value in a register, executes an instruction which pops the register state and return address from the stack, restoring the registers and program counter to those of the calling function. - How can you tell if the stack grows up or down? - Multiple ways to do this. - One answer - Make a function that calls itself and has a local variable. Compare the address of the local variable during the first call with the second. - What is a function pointer? What is in one? - Summary - A function pointer simply contains the start address of the referenced function. - Detailed - In C, a function pointer is a pointer variable that contains the address of function. The referenced function can be called by dereferencing the pointer and supplying parameters. - alloca - What does it do? How do you free the memory allocated by alloca? - Nice to know - Moves the stack pointer. Does memory allocation on stack. No need to free. - Please debug and correct this program (answers denoted by <===): test1(void) { char a[5]; int i; <=== Index starts from zero. for (i = 1; i <= 5, i ++) { a[i] = 'a' + i; printf("a[%d] = %c\n", i, a[i]); } } char * test2(void) { char buf[50]; char *ptr; ptr = buf; strcpy(ptr, "hello"); return ptr; <=== Returns dangling pointer. } main() {

char *s; test1(); s = malloc(2); strcpy(s, "hi"); <=== Should check the return pointer and errno. <=== String ends with '\0' and overwrites the buffer. s = test2(); printf("output = %s\n", s); } - What coding defects exist in the following C function? 1 2 3 4 5 6 7 char * copybuf (char str[]) { char *p; p = malloc(strlen(str) + 1); (void) strcpy(p, str); } There is no return value. The str buffer might not be null-terminated, resulting in a buffer overflow. - It does not check the return value of malloc(). Explanation: It is possible for the call to malloc() to fail and return a NULL pointer, which is then passed as the destination argument to strcpy(). The return value from the call to malloc() does not need to be cast because it is either declared as char * (in older implementations of C) or as void * which does not require a cast. - Sort an array of size n containing integers between 1 and x, given a temporary scratch integer array of size x. int tmp[x]; int j, idx, val, counter; /* Initialize scratch array to zeroes. */ memset(tmp, 0, x * sizeof(int)); /* * Keep count of how many times each integer shows up in the given array, * indexing the scratch buffer by the integer value. */ for (j = 0; j < n; j++) { tmp[arr[j]]++; } /* Put the integers from the scratch buffer back into the original array. */ idx = 0; for (val = 0; val < x; val++) { if (tmp[val] > 0) { for (counter = 0; counter < tmp[val]; counter++) { arr[idx++] = val; } } }

- Given an array arr of n characters, how would you reverse it using pointers instead of indexing into the array (e.g., arr[0])? char *front, *end, *tmp; front = arr; end = arr + (n - 1); /* Start at both ends and swap the chars until reaching the middle. */ while (front < end) { tmp = *front; *front = *end; *end = tmp; front++; end--; } - Explain how binary search works. Implement binary search for an array of integers of length #define LEN, assuming the array is already sorted. Return the index of the element if found. If not found, return -1. int mid = LEN/2; int binary_search(int[] array, int target) { /* Nothing more to look at here. */ if (mid == mid/2) return -1; if (array[mid] == target) { /* Found it. */ return mid; } else if (array[mid] > target) { /* Search first half of array. */ mid = mid/2; binary_search(array, target); } else { /* Search second half of array. */ mid += mid/2; binary_search(array, target); } } - Write a function that finds the first occurrence of a search string within another string (without using strstr()). Return -1 if no match was found. int index_of(char *src, char *search_string) { int i, j, src_len, search_len, found; src_len = strlen(src); search_len = strlen(search_string); /* Check that the search string fits in the source string. */ if (search_len > src_len) return -1; /*

* Compare chars one by one, until there's no more room for the search * string to fit in the source string. */ for (i = 0; i <= src_len - search_len; i++) { found = 1; for (j = 0; j < search_len; j++) { if (src[i + j] != search_string[j]) { found = 0; break; } } if (found) return i; } return -1; } [ Communication ] - Must have. - What forms of communication have you used within a team? Outside the team? What is the broadest scope of communications you have engaged in? Name some of the communication challeges you faced and your solutions. - What is your experience working across time zones? - How do you document and confirm a customer's requirements are accurately captured? - What types of presentations have you given? - No right or wrong answers. Goal is to characterize candidate's experiences. [ Copyright, licensing ] - What is a copyright? - What is a license? Name some examples you are familar with. - What is the GPL? What are the concerns with the GPL from commerical use point of view? [ DDL, data modeling ] - Nice to have. - What experiences do you have with data modeling? Approaches you've taken? - UML? [ Database ] - Nice to have. - How do you model a 1->1 relationship - column in table - How do you model a 1->N relationship - foreign key in '1' table - How do you model a N->N relationship - pivot table - primary keys from each table into another table - Indexing - why and why not - Faster searches - Takes more disk space - Longer inserts/deletes (have to update index) [ Debugging and tools ] - I like to walk through a problem that the candidate worked on recently to try to get into their head. - What challenges did you encounter and how did you overcome them?

- What tools did you use to debug a problem that he mentioned? - Nice to have - Use of cscope, tags, opengrok, etc. - What type of things would you look for when reviewing someone else's code? - Hopefully, this is an indicator of coding practices candidates has for own code. Good to have - scalability, performance, maintainability, etc. [ IPC ] - What are some of the options for interprocess communication in Unix application? - Multiple ways, should list at least a few. - Signal - Pipe (should know about common ancestor) - Message queues - Filesystem, file (kind of strange) - Shared memory - Memory queue - Semaphores - Sockets - Unix domain (stream vs. datagram) - inet (stream vs. datagram) TCP/UDP - fifo - What is a socket? How do you set addressing information for a socket? - A socket is a Unix (originally) abstraction for a network communication endpoint. Local addresses can be assigned explicitly or will be assigned by default for PF_INET sockets. Remote addresses are specified on the connect() (for stream sockets) or sendto() (for datagram socket) system calls. - What is Unix Domain socket? - A data communications endpoint that is similar to an Internet socket, but does not use a network protocol for communication - If I am a client of a stream socket connection, walk me through setup. - socket() - bind() - connect() - If I am a TCP server application stream socket connection, walk me through setup. - Don't need all the details. - Should mention socket(), bind(), listen(), accept(), connect(), read()/write(). - In a TCP server application, after what operation in the server can a client establish a connection? - bind(). bind() is the call that causes the TCP layer to create a new entry for the port specified. Bind assigns a local address to a socket. Once this is done, and a new connection request arrives on the bound port, the TCP layer accepts the connection. The 'accept()' call is only to return a reference to the most recently established connection. This internally causes the TCP module to move the associated tcpcb from the queued list to accepted list. - Can you call connect() an UDP socket? - Bonus points for answering. - Yes, then you can use send() intead of sendto().

- How do I know connect() succeeded with an asynchronous socket? - In non-blocking mode. - What is the difference between non-blocking IO and blocking-IO? - Talk through select() or poll(). - I/O is non-blocking when the result of a request (read/write) is received asynchronously from the sending of the request itself. - Bonus points - Non-blocking I/O is implemented differently on different operating systems. On Unix, read and write requests to a file descriptor will return EAGAIN if the file descriptor is non-blocking and no data is available. On other systems such as WIN32, I/O completion ports can be used. (Most only know FMO.) kqueue is the FreeBSD equivalent. - How do I handle multiple clients on BSD socket server application? - Use select(). - What does shutdown() (Unix system call, not shell command) do? - Shutdown gracefully closes one direction (or both) of a full-duplex socket stream connection. - What happens to your local side of a stream connection when the peer closes its side? Unix API level (not TCP/IP specifics). How do I know that the client died? - select(), read bit set, read() returns 0 - EOF. - What happens if you try to write to socket where the other side has closed the connection? - SIGPIPE. - How is SIGPIPE handled if you don't set up handler? - Aborts. - Tell me how to handle SIGPIPE and find out if this is why my call to write() failed becuase of this. - Use signal(), SIGIGN - ignore, check errno if write fails, EPIPE. - What is little endian vs. big endian? Which is network byte order? - The ordering of bytes within a 16-, 32-, or 64-bit word. Integers are usually stored as sequences of bytes, so that the encoded value can be obtained by simple concatenation. The two most common of them are: - Little endian - Increasing numeric significance with increasing memory addresses. The least significant byte (LSB) is stored first. - Big endian - The most significant byte (MSB) is stored first. - Network byte order is big endian order. - How do you figure out endianness by writing code? - Endianness can be determined by casting a pointer to a 32-bit word as a pointer to a byte, and retrieving the byte. If it's the LSB, it's a little endian machine. - Passing integers on network - How do you convert between host byte order into network byte order? - Should be familiar with these. - ntohl(), htonl(), ntohs(), htons() [ Java ] - What is the difference between AWT and Swing? - AWT (Abstract Windowing Toolkit): - Has 'heavyweight' OS-dependent 'peer' associated with every widget hence when you create a 'Frame' or a 'Dialog' you get whatever a Frame or Dialog box looks like on that platform. It's OS specific what you get. - Event model is centralized - all events pass thru an event loop which

then is parceled out to your program for you to figure out what to do - handleEvent. - Swing - 'Lightweight' - no underlying OS-dependent 'peer' associated with each widget. - Event model based on 'register/unregister' paradigm - each individual widget object can register and unregister for its own events. Event delegation model. - Why can Swing apps alter their 'look and feel' but AWT apps can't? - AWT apps uses whatever the OS provides - Swing makes it own - so look and feel can be changed. - How can you work around Java not having multiple inheiritance? - Implement interfaces. - What is the difference/when should you use StringBuffer vs. String? - Strings are static read only objects which cannot be changed. StringBuffers can be altered. Strings should only be used when you require no manipulation of your string - otherwise use StringBuffer. - What is the difference between the new Collections framework and the older 'Vector' and 'Hashtable' classes and should the older classes be used? - The older classes are thread-safe and more 'heavy'. Specifically their methods are 'synchronized'. The Collections framework provides many more useful object for Sets, Lists, and Map and should be used instead. It contains both thread-safe and non thread-safe classes. old new ------------------------------------------Vector and Stack -> LinkedList or ArrayList Hashtable and Properties -> HashMap or TreeMap - Also 'Sets' were introduced - HashSet and TreeSet - Collection frameworks objects use 'Iterator' instead of 'Enumeration' which safely supports 'remove'. - What does public/protected/private mean? What happens if you don't specify one of those? - Public: Anyone can access. - Protected: This class or subclass in same package can access subclasses in different packages can access protected members of super-class only thru itself or subclass of itself - not directly. - Private: only this class can access. - If not specified the object/field/function is 'package private' meaning accessible ONLY by object in same package. - What does a 'JIT' compiler do? - Just In Time compiler compiles and caches code ONLY WHEN SEEN for the first time from Java bytecodes to machine language. Later during the program's lifetime and that code is called again the machine code is run. - Why can't Java programs be 'real-time'? - Garbage collector runs non-deterministically. - What are the 2 types of threads in Java and talk about them and their differences. - User threads - Regular user-created threads. - Daemon threads

- Best used for 'scheduling' threads. - Threads are typically created on your behalf by the JVM - they only live to server user threads - canonical example being the garbage collector. You can mark threads as daemon threads using 'setDaemon'. Super bonus points - This call can ONLY be made after the thread has been created but BEFORE the thread starts - you CANNOT change a user thread to a daemon thread (or vice-versa) once it's running. - The ONLY time the JVM differentiaties between user and daemon threads: When a user thread exits the JVM looks for another thread to run - if there are no more user threads left then the JVM exits. - How can you create a seperate Thread if your class cannot be derived from Thread? - Implement the Runnable interface and pass your object to the Thread constructor. - What are the values of: - Thead.MIN_PRIORITY? 1 - Thead.MAX_PRIORITY? 10 - Thead.NORM_PRIORITY? 5 - Bonus points - What is the maximum priority of a thread within an applet? Thead.NORM_PRIORITY + 1 = 6 - Why is it important to actually know what these values are? - If we want deterministic behavior we gotta know what the range between min and max priority values are so we know what to set thread priorities at. - What is the default priority of a thread? - The priority of the thread that created it. - When do you want to use the thread priority mechanism? - There is only one CPU-intensive task AND - intermediate results are interesting to the user. - What is the Factory design pattern? - Encapsulates the creation of objects inside an interface. - Benefits: - Don't always have to instantiate a new object. - Single location for object creation instead of 'new's everywhere. - Use: internationalization - ResourceBundle stuff. - Types: - Concrete - instantiates objects of a class name you know at compile time. - Abstract - determine what class type to return at runtime. [ JDBC ] - What is JDBC? - JDBC is a set of interfaces implemented by vendors for their DB. - What are the different types? - Uses bridging (JDBC-ODBC driver) - requires extra code to be installed on client. - Native API - Uses JNI to call native drivers - requires extra code on client. - Uses sockets to call middleware app which translates into DB calls single driver can provide access to multiple DBs. - Talk directly to DB - 'pure' Java. - How do you use it?: - First load driver class which registers itself (like Class.forName()).

- Then get connection using DriverManager.getConnection(). - Rock 'n' roll. - What's the difference between a 'preparedStatement' and just a 'statement' using JDBC? - PreparedStatement allows you to prototype the statement and fill in values later - and those values are escaped for you. - Statement is raw text you've got to escape yourself and is a one-shot thing. [ Networking ] - What networking APIs are you familiar with? - BSD socket, WinSock, TLI, XTI, ... - Your web browser connects to http://www.dilbert.com. What happens? - nslookup, service (http) lookup, connect - Networking technologies What areas of networking technologies are you interested in and why? - This is an open-ended question, not looking for specific answers. But the pluses are IP networking, routing-protocols, VPN technologies, ethernet switching solutions, etc. For junior levels, basic networking technologies like TCP/IP, client/server, multicast, SNMP, etc. For senior levels, specifics of some of the above technologies. - Look for networking keywords in the resume and ask specific questions about those. - How does TCP module track the states of all the connections on the system? - Should mention about tcpcb, inpcb and about the queues maintained by TCP while a connection is about to be established. - What is IP multicast? Why do we need it? How does it work ? - Should talk about IGMP. Things done in the adapter driver to support this (a portion of the multicast IP is used to derive the address that will be written into the adapters EEPROM to store the multicast address MAC address). - DHCP - How it works? How does DNS work when DHCP is used in a network? - Should be able to mention about dynamic DNS update. - IP addressing - What is a 'Class - Class A begins - Class B begins - Class C begins A/B/C' network? with 0 0-127.*.*.* with 10 128-191.*.*.* with 100 192-223.*.*.*

- What use are the addresses 224.0.0.0 and up? - 224-239.*.*.* are multicast addresses. - 240.*.*.* and up are reserved. - Why aren't multicast addresses ever sub-netted? - Each multicast address already represents 1 group. - How many class B networks in a class A (class C's in a B)? - 2^8 = 256

- How many /17 networks in a /22? - 2^5 = 32 in a classless network - 30 to reserve all 0's and all 1's - How many host addresses are available in a Class C? - 254 - all 0's is net/subnet all 1's is broadcast - What netmask is needed to create 9 subnets from a Class B? - /20 (creates 16 subnets) - How many host addresses are available in one of those subnets - (2^12)-2 = 4094 - TCP/IP, UDP - What services does IP provide? - Connectionless datagram service. - Packet addressing, routing, fragmentation, and reassembly. - no error checking or order checking. - Passes data to higher level protocol (TCP and UDP). - What services does TCP provide? - Reliable data xchange - connection oriented. - Reorders. - Fragments and reassembles. - Retransmits if loss. - Error checking on packet contents. - Passes good data up to higher level protocols. - Describe - Client - Server - Client TCP connect sequence/handshake. sends SYN with seq#=X. responds SYN w/seq#=Y, ACK=X+1. responds ACK=Y+1.

- Why does server response with 2 numbers? - Security. - Describe - Client - Server - Server - Client TCP 'active' vs. 'passive' teardown sequence using 'FIN'. sends FIN=X. ACK=X+1. sends FIN=Y. sends ACK=Y+1.

- What about RST? - Close immediately. - What services does UDP provide? - Unreliable data xchange - connectionless. - No error correction or re-transmitted of bad packets. - What uses it? - NIS, NFS, NTP, DNS, SNMP - What does UDP provide over IP? - Port numbers. - Why use it? - Lower overhead. - Good for request/response with small # of messages. - Some applications are better off ignoring bad packets and continuing on rather than trying to get them to the user again and interrupting the output, e.g., streaming video or audio. [ SNMP ] - What is SNMP? - Simple Network Management Protocol.

- What operations can you do in SNMP? - get, getnext, getbulk, set, response, trap - What is the difference on SNMP v1 and v2c? - 64-bit Counter, getbulk, new v2 trap format - v1 has simple community string based security. - v2c still has community strings (v2p has a complicated privacy scheme that was never productized by anyone). Also includes GetBulk, improved traps, updated SMI. - What is the difference on SNMP v2c and v3? - v3 uses the same packet formats as v2 but has an improved and simplified security model. - What is management information base (MIB)? - A collection of managed objects residing in a virtual information store. Collections of related managed objects are defined in specific MIB modules. - What is the syntax notation used in the MIB file? What encoding rule is being used? - ASN.1, BER (basic encoding rule) - What is Structure of Management Information (SMI)? - The SMI defines the rules for describing management information. - What is SMI Data Type? - Integer, Unsigned32, Counter32, Counter64, Gauge32, Timeticks, Octet String, ipaddr, Object identifier, Opaque [ Security ] - What is dangerous about strcpy? Is there an alternative? - Potential buffer overflow. Overwriting memory that might be in use. - If no answer right away, ask if candidate uses strncpy and why. - Which line of code poses a security risk, and why? 1 #include <stdio.h> 2 #include <string.h> 3 4 #define SIZE 1023 5 6 void 7 usage (char *command) 8 { 9 char buf[SIZE]; 10 snprintf(buf, SIZE, "Usage: %s <target>\n", command); 11 printf(buf); 12 } 13 14 int 15 main (int argc, char *argv[]) 16 { 17 if (argc == 1) 18 usage(argv[0]); 19 return 0; 20 } - Line 11. This program is susceptible to a format string vulnerability because an attacker can provide a malicious argument for argv[0] which, when

interpreted by the call to printf() on line 6, can result in an arbitrary write. The call to on line 5 is not susceptible to a buffer overflow because the snprintf() function is used, which limits the amount of data written to destination buffer. - Cryptography - Explain symmetric vs. asymmetric cryptography. - Symmetric: - Shared secret used to encrypt data. - AES and Blowfish are examples - Problems: - How to share the secret if you don't have a secure channel. - After a while lots of captured text can reveal pattern (stereotypes). - Mitigated: - Use modes that perturb the encryption (Cipher Block Chaining, for example) with initialization vectors - Switch shared keys continually. - Asymmetric (public key/private key): - Encrypted with one key and decrypted with another (and vice-versa). - 'Public key' is shared w/everyone - private key kept private. - Used to generate a shared secret and then symmetric is used since asymmetric is very slow (hybrid cryptosystem). - Session keys are encrypted/decrypted by public/private key and the actually message is decrypted/encrypted by the session key. - What is the Diffie-Hellman key exchange algorithm (PKCS #3)? - A and B share two numbers and each pick a large int randomly - then do some math and share the result which each uses to compute the shared 'session' key. - What is RSA (PKCS #1)? - Uses public/private keys to share a secret key - encrypt with one and decrypt with other. Requires 'trust stores' to ensure A's public key is really A. - What is PGP? - Pretty Good Privacy - Uses public/private keys to share a secret key - encrypt w/one and decrypt with other. Requires 'web-of-trust' to ensure A's public key is really A. - What are message digests? - Fixed-length message 'summaries' used as signatures. - Have the following security properties: - Collision-free (two pre-images don't hash to the same digest) - Pre-image resistance (can't get pre-image from digest) - Second pre-image resistance (can't find a second pre-image that makes the same digest) - MD5, SHA-1 in wide use, MD2 is obsolete - Transition to SHA-2 (SHA-224, SHA-256, SHA-384, SHA-512) - NIST holding competition for new hashing algorithm - What are stream ciphers (seed value is key)? - Operate on streams of plaintext and ciphertext one bit or byte at a time. - RC4 is used in SSL - What are certificates? - A certificate is a data package that completely identifies an entity,

and is issued by a Certification Authority (CA) only after that authority has verified the entity's identity. The data package includes the public key that belongs to the entity. - X.509 protocol defines a structure for public key certificates. - What are some of the protocols for securing information flows over the Internet? - SSL/TLS, used in web applications, for VPNs - SSH, Secure Shell, useful for logging into a remote machine, also supports tunneling - IPsec, protocol suite that authenticates and encrypts each IP packet of a data stream, operates at Layer 3 (vs. SSL and SSH which work at upper layers) [ Shell, shell scripting ] - Must have for installation. - What sources of info do you use to find out about commands and arguments? - Man pages, Info pages, README, commands with '-h' option. - Explain in some detail how the shell starts an editor. - Shell resolves the path of the editor program on disk, then calls fork. Child then execs editor. - What does ps do? Why would you use it? What are some typical options for i t? - Shows information about running processes. 'a' shows all users' processes, 'x' shows processes with no controlling terminal, 'w' widens display (more = wider). If they are more familiar with SunOS they may mention 'e' and 'f' instead of 'a' and 'x'. - How do you set up a pipelines/why do Unix processes traditionally have stdin/stdout? - Use '|' in shell--connects stdout of first process to stdin of second. Can chain arbitrarily many of these together. - What happens when multiple processes try to open the same file? Delete? - Works fine. A file that is deleted while opened by a process stays around for the process while it is still open (this is opposite of Windows). - How do you kill a bunch of processes with the same name? - Use pkill, or some elaborate chain of pipes. - How does the remote end indicate EOF on its stdout? - shutdown(s, SHUT_WR) - In shell scripting, what are $? and $- ? - $? = return value, $- = all input to script - What is the difference between $* vs $@ vs "$*" vs "$@"? - For a given command line: foo a b "c d e" Without quotes they are equivalent. "$*" is equivalent to "a b c d e" (i.e. removes all quoting and leaves as single space-separated string). "$@" is equivalent to "a" "b" "c d e" (i.e. preserves line items with spaces). - What does 'trap "" 0' do? - Removes any actions previously assigned to run at the normal exit of a

shell. - How do you delete a file named -? - rm ./- rsh host wc -l </etc/motd vs cat /etc/motd | rsh how wc -l How does it work? - rsh opens a connection to host and runs the wc command on host with the stdin of wc (remote) fed by the local file /etc/motd. - For the fragment: foo=a while ... do ... foo=xyz done < bar echo $foo What is echoed? - 'a', because the while loop is implicitly run in a subshell. - Explain line endings (Unix vs. dos vs. old Macintosh). - Unix: \n - DOS: \r\n - Obviously the Unix one is correct. :-) - What does sed do? Give an example of how to use it. - sed is a line editor that can be used to filter and modify files using regular expression. - How do you search for a string in all files in a directory? - Basic question. - Use grep. - How do you navigate a source tree (find where function 'foo' is called). - Find command. - Command line for SCM tool. - Use of cscope/tags/opengrok/etc. - What is the Unix philosophy? - Small focused tools that can be strung together with pipes. [ Team experience ] How big was the team to start with? How big did it grow? What is the largest team you've worked in? Smallest? Which project have you learned the most from, either technically or non-technically? What did you learn? What was your role in the position? Why did you choose a certain technology over others? What best coding/design practices did you pick up from your experience? Why are you leaving <current company>? - No right or wrong answers. Goal is to characterize candidate's experiences.

[ Test design and implementation ] - What are the differences between unit-testing, development testing and system testing?

Unit testing should be exercising the code from the code point of view, making sure that all the code-paths are exercised and all the boundary conditions are accounted for. Development testing would be a bridge between unit-testing and system testing, since most of the features are extensions or new capabilities in existing features. Development testing would make sure that the new changes did not break existing features, and the transition from the old behavior and the new behavior are not conflicting. For Juniper specifically, many features are requested by particular customers to solve particular problems. Devtest usually have knowledge on how those customers have their network designed. This would be a good group to test how well the features work in the particular customer network settings. System testing would be testing the functionality of the feature on a system. This should be exhaustive testing on all functional scenarios plus negative testing. In general, testing should include - Basic feature functionalities. - Scaling and performance. - Negative testing. - Feature interactions. - Manageability. [ Threading, SMP ] - Preemptive Multithreading - What's the difference between creating a new thread and a new process (pthread_create vs. fork)? - Thread shares data segments. - Process shares only text segment (fork). - Both have own stack. - How to exchange two 32-bit values? - Atomically (inline assembler). - Mutex-lock. - Spin-lock (SMP). - What is synchronization? How does the Unix kernel implement this? - Using locks. Should be able to talk about mutex lock. - How do you use locks - example? Why do u need them? - If the candidate has exposure and has worked, would be able to mention about locks design like locks per subsystem modules (network, filesystem, SCSI, etc). - What is interrupt priorty level in terms of Unix kernel? - If candidate has good knowledge on x86 then he should be able to talk about APICs, local APIC, I/O APIC, interrupt descriptor table. - How are interrupts of different priority levels handled? - This depends on the OS. The ipl mask is used on the APIC to prevent any interrupts lower or equal to the value set from interrupting the processor now. - What is a condition variable? Where might you use one? How do you use one? - Synchronization object that allows multiple waiters to get notified and check the condition they are waiting for.

[ Unix ] - Must have. - In 30 sec or less, tell me how a Unix system boots. - BIOS loads boot sector from HD into memory at a given address and jumps there. - 1st boot loader might load 2nd boot loader. - Boot loader loads kernel and jumps to it. - Kernel sets up PDT. - Kernel mounts root fs. - Kernel starts init process as PID 1. - init reads rc file(s) and executes. - rc files typically start getty on one or more consoles. - How does a process execution start? - This is just to get an idea as to how deep is the understanding. If the knowledge is good - should be able to mention: a) Execve system call. b) Virtual memory usage - loading the executable onto physmem. (Can dig more on VM to physmem translation.) c) ELF. d) Who calls 'main' of the program being exec'd. - 2 processes open same file - what would be the descriptors (assuming that this is the first and only open() call in both the applications) and why? - fd is 3 in both apps. File descriptor table is a per process entity. If need be, can dig more on vnode, vfs. - How do you create a new process in Unix? - fork(). - When you fork, how does the child compare to the parent? - Looking for copying of process space, file descriptors, etc. - How expensive is fork()? - Useful as a general conversation starter. - copy-on-write, copies of file descriptors and how to close them all (or use rfork()), etc. - And don't forget vfork(). If they sound like they know something, ask what one calls to exit a child after vfork - answer _exit(). Why? to avoid double flushing of i/o streams etc. - If I am the child process, how do I execute a new application? - Looking for exec(). - How does the parent know the child is gone? - Receive SIGCHLD and/or calling wait() or waitpid(). - Now that parent has gotten SIGCHLD, what does it do? - Should wait(). - How does the parent know if the child is successful or not? - Called wait(), integer variable, status of child. - What happens if the parent dies? What happens to the child? - Inherited by init. - How does a Unix process become zombie? - Parent still there, until it waits for child, child is zombie. - A process becomes a zombie after it has called exit(2) and died. Remains one until its parent calls wait() to retrieve its exit status. - How do you kill a zombie? - Can either cause the parent to call wait(), or kill the parent, which will cause init to inherit the zombie child and call wait() on it. - Say I'm a server application, and I'm not using threads, how do you handle

multiple clients at the same time in Unix? - Two ways, looking for fork a process per connection or use select() and do things asynchronously. - Explain things that happen when a system call is issued. - Should be able to talk about sysent, lcall. If the person has knowledge on x86 architecture then, he should be able to talk about call gates, global-descriptor-table. - Explain what happens when read on a file is done - explain end-to-end. - Should be able to mention: a) System call switch to kernel mode. b) File pathname lookup. c) Virtual file system module and its purpose. d) How the file system specific XXX_read gets invoked. e) vnode, in-core inode. f) Ef candidate has knowledge on SCSI should be able to talk about how the SCSI driver breaks the I/O request into multiple I/O requests (when and why - general logic is to break the I/O request based on the block size supported). - What is a shared library. How do they work? - A shared library is a collection of common functions (and possibly data) that can be shared between multiple running processes. As opposed to the text of a program that is shared by all instances of that program, the shared library is shared by all processes that use it. Shared libraries are linked into an executing process at run time, using a dynamic linker provided by the operating system. The executable image contains a table describing the symbols it requires resolved in order to execute. When the executable image is loaded, the run-time loader constructs a table through which calls into the shared library are resolved. [ Web ] - What is the difference between GET vs. POST? - GET args via command line to CGI and in URL. - Length limit. - Looks ugly. - POST args via stdin to CGI script. - Explain servlet life-cycle. 1. Load and Instantiate Before a servlet can be loaded, the servlet engine must first locate its class. A servlet class may reside on the local filesystem, a remote filesystem or be some other network resource. The servlet engine must know how to locate the servlet and then use the usual Java class loading facilities to load the servlet class into the JVM. Once loaded, the servlet engine instantiates an instance of that servlet class. 2. Initialization Before a servlet can be loaded, the servlet engine must first locate its class. A servlet class may reside on the local filesystem, a remote filesystem or be some other network resource. The servlet engine must know how to locate the servlet and then use the usual Java class loading facilities to load the servlet class into the JVM. Once loaded, the servlet engine instantiates an instance of that servlet class.

During initialisation the servlet has access to two key objects: ServletConfig and ServletContext. ServletConfig contains configuration information for the servlet in the form of name/value pairs. How this information is passed to the servlet engine is web server dependent. However, in version 2.2 of the servlet specification, initialisation information is encoded as XML that is parsed and loaded by the servlet engine. From ServletConfig, the servlet developer can get a reference to the ServletContext object. ServletContext gives the serlvet access to information about its runtime environment such as web server logging facilities, version info, URL details, web server attributes, and so on. public void init(ServletConfig config) throws ServletException { super.init(config); ServletContext context = config.getServletContext(); The first line of init() should always be super.init(config). This allows GenericServlet to save a reference to ServletConfig and make it available to methods outside of the init() callback. GenericServlet exposes a convienence log() method so you don't need to get the ServletContext to log information to the web server. Secondly, web server logs tend buffer information for performance reasons, so during development it may be better to use System.out for viewing debug messages. In the event of errors occurring during the initialisation phase, the servlet instance can throw an UnavailableException or ServletException. These exceptions signal to the servlet engine that initialisation failed and that the servlet cannot service client requests. The servlet engine must acknowledge this, release the servlet instance and put it up for garbage collection. Note that in this case the destroy() method is not called because the servlet instance never completed initialisation. If a servlet has failed to initialise, the servlet engine may want to re-try with a newly instantiated servlet instance. However, if during the first initialisation the servlet it failed to grab a database connection, the servlet developer may want the servlet engine to wait 10 seconds before re-trying. This can be done by throwing an UnavailableException and specifying the minimum number of seconds that the servlet must remain unavailable. To tell servlet container to wait 15 seconds before trying to init this servlet again: throw new UnavailableException( 15, this, "error message"); 3. Service requests At this point, the servlet is ready to receive client requests. It is imperative that servlets be developed to run within a multi-threaded runti me environment. There is one servlet instance servicing multiple client requests. Actually - one servlet instance per registered servlet name. 4. Destruction The decision of when to destroy a servlet instance again rests on the shoulders of the servlet engine. The servlet specification makes it clear that the lifetime of a servlet can be as short as a few milliseconds to as long as the life time of the servlet engine itself. Servlet developers should not be concerned with these details, but instead focus on what should be done when the time comes. The servlet interface provides the destroy() callback method that is

called before the servlet engine can release a servlet. Inside the destroy() method the servlet developer should save any persistent state, release (handles to) shared resources such as database connections and carry out any caretaking tasks. Once the destroy() method has completed the servlet engine releases the servlet and makes it eligible for garbage collection. Before this servlet is released, it closes its JDBC database connection. However, the above code is not written in a thread-safe manner because we are not synchronizing access to the servlet's instance variable fConnection. The reason for this is that destroy() is executed within a single thread. In fact, before the servlet engine can call the destroy() method, it must allow all threads currently executing in its service() method to complete. Note that the init() method should, in theory, also be thread-safe. But it is better to be safe than sorry and implement both init() and destory() so that they can run within multi-threaded environments. - Difference between 'ServletException' and 'Unavailable Exception'? - A ServletException signals that an error has occurred during the request and some caretaking needs to be taken by the servlet engine. Note that throwing ServletException could result in a bad response being sent back to the client. The UnavailableException can have more far reaching consequences on the lifetime of the servlet instance. If the servlet signals that it is permanently unavailable, by throwing: new throw UnavailableException(theServletInstance, "no more free prizes" ); then the servlet engine gracefully removes the servlet instance from service and calls its destroy() method. If the servlet signals temporary unavailability by throwing: new throw UnavailableException(25, theServlet, "lost database connection "); then a well-behaved servlet engine will not route client requests to the servlet but instead return the HTTP response SERVICE_UNAVAILABLE(503) status along with a Retry-After header that tells the client when the service will be back up. However, servlet engines are not being held to this by the specification and they could quite easily treat temporary UnavailableExceptions as permanent. Read your servlet engine document because in this case, throwing temporary UnavailableExceptions will cause that servlet to be permanently removed from service! [ XML, XSLT ] - What are XML and XSLT? - XML stands for Extensible Markup Language. It is a self-describing data format that can be used to define markup languages for many kinds of data. XSLT stands for XSL Transformations (XSL is Extensible Stylesheet Language). XSLT is a language used to define transformations from XML to [XML, XHTML, text]. - What is a namespace and how do you declare one? - Just a hunk of letters - typically in the form of a URL but not

necessarily and the URL doesn't need to point to a 'live' web page. <blot:foo xmlns:blot="sdlkdsf"> - What is a default namespace? - Default namespace does NOT apply to attributes. <foo xmlns="sdlkdsf"> That puts 'foo' in the 'sdlkdsf' namespace. - What namespace are attributes in? - Namespace of parent EXCEPT for default namespaces. - What's SAX and DOM, advantages/differences - SAX = Simple API for XML processing. - Callbacks for each XML object. - Entire doc NOT in memory all at one time. - Gotta keep global state info. - Can't go back. - DOM = Document Object Model - Tree representation of XML doc. - Entire doc in memory. - Easier to pick out pieces for random access. - What's the difference between DTD and XML schema? - DTD = Document type definition - Non-XML syntax. - No namespace support. - Extremely limited datatyping (for attributes ONLY). - No numbers, dates, currency, etc. - Have no ability to express the datatype of character data in elements. - Complex and fragile extension mechanism based on little more than string substitution. - XML Schema = heirarchies - choices, enumerated types - type checking. - Richer datatypes. Booleans, numbers, dates and times, URIs, integers, decimal numbers, real numbers, intervals of time, etc. - In addition to these simple, predefined types, there are facilities for creating other types and aggregate types. - User-defined types - and can be 'sub-classed'. - Attribute grouping. - "Inheritance" of types. - A content model defined by a DTD is "closed": it describes only what may appear in the content of the element. XML Schema admit two other possibilities: "open" and "refinable". - Namespace support - What's the different between 'xsl:copy' and 'xsl:copy-of'? - copy-of makes copy of current node, child nodes, and attributes. - Copy just copies current element - no attributes or children are copied (but namespace attributes are). - What does 'xsl:value-of' do? - Evaluates expression and extracts value. - When should you use 'xsl:if' vs. 'xsl:choose'? - Use 'if' for testing only 1 possible value since there's not 'else'. - Use 'choose' for a case statement to test against mutiple values using 'when' and use 'otherwise' at end if nothing matched. - What's the diff between xsl:param and xsl:variable? - Bonus points for answering. - Variable is immutable. - Can only be changed from within a for-each loop.

- Params are assigned a value either from the process that invoked the stylesheet or from a <xsl:with-param> or with a default value. Using 'with-param' and a default value: <xsl:template match="/"> <xsl:call-template name="blob"> <xsl:with-param name="par" select="'some-value'"/> </xsl:call-template> </xsl:template> <xsl:template name="blob"> <xsl:param name="par" select="'default-value'"/> <xsl:value-of select="$param"/> </xsl:template>

You might also like