Juniper Networks On-Site Interview

Disclaimer: I signed an NDA and am not sure if I should be posting these questions or not.

Interview 1
-----------
Q: Lot of questions on 802.1q [vlan] and its implementation in SmartEdge Router. What is your role in your team? Explain what your module does and how it supports this protocol on SmartEdge?
A: I explained everything. It appeared to me that the interviewer was interested in implementation of 802.1q in forwarding plane rather than RP/Control Plane.

Q: static int i is defined in file a.c and i want to access it from file b.c. Will extern static int i help?
A: The interviewer said its a very basic C question. But I didn't have good answer for it. I realized my interview is going down the drain. I found a very good answer for this question on Stackoverflow.

Q: If we don't want to use 'extern' keyword, how can we access it?

Q: Big-Endian & Little Endian 0x01020304. How does it look in BE and LE
A: I answered BE: 0x04030201 and LE: 0x01020304. I learnt later that its the other way round.

Q: what happens when you run this program?
void func()  
{  func(); }

main()  
{ func();  }

A: I said the system will crash due to stack overflow. Stack overflow's due to return address being pushed continuously on to the stack without a termination condition.


Interview 2
------------
Q: Again lots of questions on 802.1q

Q: In a GDB coredump file, how do you detect if there were any loops? Meaning, if the process was consuming 100% CPU and user forced a coredump on it, as an engineer, what do you look for to identify loops?
A: I didn't have a good answer. A reasonable answer would be, see if the code being called is within a for/while loop. Check for termination condition on that loop.

Q: If stack memory is corrupted, how to do you recover info from coredump.
A: I have no idea.

Q: Have you written any scripts for GDB?
A: Yes

Q: Write a string copy function.

int str_copy(const char * src, char *dst). 

A:
   for(int i=0; src[i] != `\0`; i++) {

      dst[i] = src[i]; 

   }

Q: What if length of dst is less than src?
A: Memory corruption.

Q: How will you fix it?
A: There needs to be a way to know the length of `dst`. If its passed then do the following.

int str_copy(const char * src, char *dst, int dlen) {
    int i, slen; 

    len = strlen(src); 

    if(slen > dlen) {  
        /* throw an error and return */ 
    }

    for (i=0; i<slen; i++) 
        dst[i] = src[i]; 

    /* return success */
}

Q: What if the src and dst addresses are overlapping? 
A: Instead of copying from beginning, copy from the end of the string.

Q: 

 //a = 5

  test(a) {  
     inc(a); print(a); 
     INC(a); print(a); 
     inline_inc(a); print(a); 
  }
inc(a) is a regular function, INC(a) is a macro, inline_inc(a) is an inline function. What values are printed at all the 3 prints?
A: I answered 5, 6, 7. Correct answer is 5, 6, 6.

Q: int str_copy(const char * src, char *dst). Why was 'const' used there? 
A: So as not to change source string.


Q: What would you do to make sure that the pointer remains constant? 
A: Change first argument to: const char * const src

Q: Where does malloc allocated memory from? 
A: Heap 

Q: Can you read from the memory location that has been freed? What would you read? 
A: Technically, we are not supposed to do that. We can de-reference a pointer that has been freed. But the data integrity is not guaranteed. 

Q: Can you write to memory that has been freed? What happens? 
A: Our code can do that. But when running, system may crash with NULL pointer exception.   

Q: Difference between binary semaphore and mutex. 
A: I said they are same. But they aren't. A thread that is calling a mutex lock can unlock it. No other thread can unlock it. It is the "owner" of the mutex. Whereas with binary semaphore, one thread can call and lock the semaphore while some other thread can unlock it. There is a very good discussion on Stackoverflow.


Q: How do you detect loops in linked list. 
A: Its a pretty standard interview. As usual, Stackoverflow has a very detailed and varied ways to solve this problem.


Interview 4
-----------
There was only one technical question asked and I posed this question on Stackoverflow. The community gave very good answers and another viewpoint of what the interviewer could be expecting.

Labels: , ,