techpreparation-homepage

Home  Interview Questions  Aptitude Questions  Tutorials  Placement Papers  Search  Resume Guide  Soft Skills  Video  Forum  Blog


Technical Interview Questions

Linux Interview Questions
.NET Interview Questions
Java Interview Questions
OS Interview Questions
                              .........More

Soft Skills
Communication Skills
Leadership Skills
                              .........More

Subscribe to our Newsletters
Name:
Email:

 

 

  

Windows Programming Interview Questions and Answers

What happens when the CloseHandle(handle) is called?
This function first checks the calling process’s handle table to ensure that the index (handle) passed to it identifies an object that the process does in fact have access to. If the index is valid, the system gets the address of the kernel object’s data structure and decrements the usage count member in the structure; if the count is zero, the kernel destroys the kernel object from memory.

You forget to call CloseHandle - will there be a memory leak?
Well, yes and no. It is possible for a process to leak resources (such as kernel objects) while the process runs. However, when the process terminates, the operating system ensures that any and all resources used by the process are freed—this is guaranteed. For kernel objects, the system performs the following actions: When your process terminates, the system automatically scans the process’s handle table. If the table has any valid entries (objects that you didn’t close before terminating), the system closes these object handles for you. If the usage count of any of these objects goes to zero, the kernel destroys the object.

What is the need of process relative handles?
The most important reason was robustness. If kernel object handles were system-wide values, one process could easily obtain the handle to an object that another process was using and wreak havoc on that process. Another reason for process-relative handles is security. Kernel objects are protected with security, and a process must request permission to manipulate an object before attempting to manipulate it. The creator of the object can prevent an unauthorized user from touching the object simply by denying access to it

How the handles are handled in the child process?
The operating system creates the new child process but does not allow the child process to begin executing its code right away. Of course, the system creates a new, empty process handle table for the child process just as it would for any new process. But because you passed TRUE to CreateProcess’s bInheritHandles parameter, the system does one more thing: it walks the parent process’s handle table, and for each entry it finds that contains a valid inheritable handle, the system copies the entry exactly into the child process’s handle table. The entry is copied to the exact same position in the child process’s handle table as in the parent’s handle table.

Why the entries in the parent process table and child table are same?

It means that the handle value that identifies a kernel object is identical in both the parent and the child processes.

What about the usage count in the parent child process tables?
The system increments the usage count of the kernel object because two processes are now using the object. For the kernel object to be destroyed, both the parent process and the child process must either call CloseHandle on the object or terminate.

What are Named Objects?
Method available for sharing kernel objects across process boundaries is to name the objects. Below are the kernel named objects:
1) mutex,
2) Events,
3) semaphore,
4) waitableTimers,
5)file mapping,
6)job object.
There are APIs to create these objects with last parameter as the object name.

What do you mean by unnamed object?
When you are creating the kernel objects with the help of API’s like CreateMutex(, , , ,pzname). And the Pzname parameter is NULL , you are indicating to the system that you want to create an unnamed (anonymous) kernel object. When you create an unnamed object, you can share the object across processes by using either inheritance or DuplicateHandle

What is DuplicateHandle (API)?
Takes an entry in one process’s handle table and makes a copy of the entry into another process’s handle table

What is a thread?
A thread describes a path of execution within a process. Every time a process is initialized, the system creates a primary thread. This thread begins executing with the C/C++ run-time library’s startup code, which in turn calls your entry-point function ( main , Wmain , WinMain , or WWinMain ) and continues executing until the entry-point function returns and the C/C++ run-time library’s startup code calls ExitProcess

What is the limit on per process for creating a thread?
The number of threads a process can create is limited by the available virtual memory and depends on the default stack size

Page Numbers :   1           2           3

Have a Question ? post your questions here. It will be answered as soon as possible.

Check HTML Interview Questions for more HTML Interview Questions with Answers

Check Job Interview Questions for more Interview Questions with Answers