Microsoft Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

I found a very nice explanation somewhere, so am pasting it here :

A process is an executing instance of an application, for example when we double click on MSWord, a process is launched. A thread on the other hand is only a path of execution within a process.
A process can contain multiple threads. When you start Word, the operating system creates a process and begins executing the primary thread of that process.

A thread can do anything a process can do. But since a process can consist of multiple threads, a thread could be considered a ‘lightweight’ process. Thus, the essential difference between a thread and a process is the work that each one is used to accomplish. Threads are used for small tasks, whereas processes are used for more ‘heavyweight’ tasks – basically the execution of applications.

Another difference between a thread and a process is that threads within the same process share the same address space, whereas different processes do not. This allows threads to read from and write to the same data structures and variables, and also facilitates communication between threads.

- teli.vaibhav October 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

Process
Each process provides the resources needed to execute a program. A process has a virtual address space, executable code, open handles to system objects, a security context, a unique process identifier, environment variables, a priority class, minimum and maximum working set sizes, and at least one thread of execution. Each process is started with a single thread, often called the primary thread, but can create additional threads from any of its threads.

Thread
A thread is the entity within a process that can be scheduled for execution. All threads of a process share its virtual address space and system resources. In addition, each thread maintains exception handlers, a scheduling priority, thread local storage, a unique thread identifier, and a set of structures the system will use to save the thread context until it is scheduled. The thread context includes the thread's set of machine registers, the kernel stack, a thread environment block, and a user stack in the address space of the thread's process. Threads can also have their own security context, which can be used for impersonating clients.

- GaëTaN October 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

another difference is that processes are "fork"ed and threads are "spawn"ed.

A fork (creating a process) is usually more time-consuming. This is a system call.

A spawn (creating a new thread) can be faster than forking a new process.

The first time you run a program, you create a new process (never a new thread). A process can have multiple threads, but not the other way around. (edited and corrected)

- gokayhuz October 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Pardon? Are you sure we can create a thread without invoking a system call into Kernel at some point?

fork is a linux/unix system library function to create a new process identical to the calling one

Are you sure spawn means create new thread, instead of fork+exec ?

"pthread_create" creates a new thread on unix/linux

both pthread_create and fork call "clone" on linux (they both require the linux kernel's intervention)

- Urik's twin Cookie Monster (dead now) October 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It definitely is possible to create User Level Threads without a system call, but you are right, this does not have to be so, as there are also Kernel Level Threads.

- gokayhuz October 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

what library call on linux, for example?

- Urik's twin Cookie Monster (dead now) October 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Threads are easier to create than processes since they
don't require a separate address space.

2. Multithreading requires careful programming since threads
share data strucures that should only be modified by one thread
at a time. Unlike threads, processes don't share the same
address space.

3. Threads are considered lightweight because they use far
less resources than processes.

4. Processes are independent of each other. Threads, since they
share the same address space are interdependent, so caution
must be taken so that different threads don't step on each other.
This is really another way of stating #2 above.

5. A process can consist of multiple threads.

- codeAddict January 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Context switching among process takes more time..
Context switching among threads takes less time...

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

Suppose I have a program that does the following steps
1. Read a file
2. Read data from a database
3. Compute some values from the info in the file received and the data
4. display something on the screen

When this is realized into code, its a program. When the program is executed, an image of it is created (with some resources such as file handle, etc.) and loaded into main memory and scheduled to run on the processor. Now its a process. Single program be used to instantiate multiple processes.
If we look closely, we can perform steps 1 and 2 independently, then 3rd and then 4th. Do we really need to wait for 1 to finish before beginning 2? To make things work parallel, we can run 1 and 2 parallel in smaller partitions of the process. This partition of the process, which has some resources inherited and its own context within the process is a thread. Threads are lighter weight and help improve throughput since we don't need to wait for executing independent tasks even within a process.

- NachiketN.89 February 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

>thread share the address space of the process that created it.process have their own address space
>threads can directly communicate with other threadsof its process .process must use interprocess communication mechanisms (pipes ,sockets)to communicate with each other

- gaurav mishra March 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A process can contain multiple threads.
That is to say that a thread is the smallest unit of execution of a process.
A process can basically be divided to have two units-

1.Resource ownership
resources like virtual address space , main memory , I/O devices and files are owned by the process

2.execution unit->this is the one that is generally often called thread
this unit is totally independent from the resource ownership unit.

threads have their shared address space and individual private address space.
They are a means to divide a process into various modules that can execute independently.

- neerajlakhotia08 May 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

ROFL man

- Anonymous January 07, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

LOL

- Anonymous February 15, 2014 | Flag


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