Microsoft Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
8
of 8 vote

Normally processes have their own address spaces and this address space is not visible from other processes (but read: interprocess communication - how to create a visible address space that is shared between two or more processes). This is the usual case but there are operating systems (some embedded systems for example) where it is not the case, protected memory/separate address space is "expensive" (read: task switch penalty)

Threads do share the same address space, so in case of threads the answer is yes.

- Selmeczy, Péter January 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Even in the case of threads, you'd need to be careful when updating. Another process may have its own cached versions of those variables, and in the absence of synchronization, there may not be strong guarantees as to when a particular variable is read anew from memory.

- eugene.yarovoi January 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
3
of 3 vote

I believe it should be possible via shared memory. While using shared memory, we attach that shared memory to the address space of our process. So, shared memory becomes part of the address spaces of both the processes. Although, we need to do some synchronization b/w the two processes accessing the shared memory.

- Nayan January 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I doubt that.
You can't use a pointer because there's no way to ensure that the shared memory is mapped at the same address in both processes. One process would no have idea what to do with a pointer into the other process' virtual address space.

So instead, you store the offset into the block of shared memory. Both processes know exactly what the 712th byte of the block of shared memory is. To access such an offset, you add the offset to the base address at which the block of shared memory is mapped in this particular process, and that creates a pointer you can use within that particular process.

- TrippingBilly March 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I agree with Nayan. The shared memory area isn't accessed by same memory map by the two processes. So when one process writes data to the buffer (and also the size of writen data), the other process reads those many bytes. Usually, there's a pre-defined op-code list to which the request is compared and the right event is triggered. (trivia: IPC on one core can be optimized by using better algo than op-code list, but for multi-core arch, op-code list seems the common way to get things done.) The response is pasted along with the size. These request/response messages to shared mem form an integral part of sw debugging. More comments are welcome.

- RD April 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

A process cannot change or alter variable of another process as they all have their own memory space. As peter suggested you can use IPC methods like 1)message passing 2) shared memory.

You can use threads to achieve your goal.(pthreads, tbb, openmp)

- Wayne January 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How do debuggers work?

- Anonymous January 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

it depends upon the situations okay. if the variable which is pointed by the pointer in other process in not global or shared then its sure that the process will crash because of the segmentation fault generated by the os and signalled to the process which wants to change it .
but wait!! if the variable is shared one then it can be easily modified by the other process .

- geeks January 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i think in case of c programing you can do so by using keyword extern in process in which you want to do so......!! the pointer can be made to store the address of the extern variable.......!! in case of shared memory also it is possible.......!!

- Anonymous February 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

volatile keyword is yet another option.. (for c/c++) before a variable if you type volatile then that tells the compiler that the variable can be changed from outside the program as well...

- anonymous February 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If it is declared in the process that owns the variable that it can be accessed and modified externally...then it can be done...or else I believe that a segmentation fault may be raised

- Atri January 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

It should be possible. But the module/program for both the processes should be coded by in such a way that, altering a variable of a process by the other shouldn't cause any data loss, or alternation.
So basically such programs are coded by a single team who knows behavior of both the processed.
And, if the processes/code are developed by different teams having no knowledge on the other process. In such cases above operations may lead to crashes.

- Vijay Rajanna January 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Who cares about data loss. The question is simply whether the variable can be changed or not.

- Thomas Edison May 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

volatile keyword is yet another option.. (for c/c++) before a variable if you type volatile then that tells the compiler that the variable can be changed from outside the program as well...

- anonymous February 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

volatile keyword is yet another option.. (for c/c++) before a variable if you type volatile then that tells the compiler that the variable can be changed from outside the program as well...

- anonymous February 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

volatile keyword is yet another option.. (for c/c++) before a variable if you type volatile then that tells the compiler that the variable can be changed from outside the program as well...

- anonymous February 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Sorry for the multiple posts on volatile keyword answer.... the net connection is so bad here... and I clicked on submit button multiple times!!

Kindly ignore those repeated answers...

Sorry...

- anonymous February 09, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More