0% found this document useful (0 votes)
3 views

SolvedQuestions

Uploaded by

zestswop
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

SolvedQuestions

Uploaded by

zestswop
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

Patni Computer System

1) What Runtime_Class feature does?


Ans. To determine the exact class of an object at run time.
This ability is most useful when extra type checking of function arguments is needed and when you
must write special-purpose code based on the class of an object.

2) How thread begins?

Ans. Thread can be initiated by

1. CreateThread win 32 api function.

2. AfxBeginThread Mfc Function.

3) How to create UI thread and Worker thread?


Ans. To create UI thread:

4) What is Worker and UI thread?


Ans.Worker threads : Worker threads have no message pump: for example, a thread that
performs background calculations in a spreadsheet application.

If you want a user-interface thread, pass to AfxBeginThread a pointer to the CRuntimeClass


of your CWinThread-derived class.

UI thread : User-interface threads have a message pump and process messages received from
the system.

If you want to create a worker thread, pass to AfxBeginThread a pointer to the controlling
function and the parameter to the controlling function.

5) What is Race conditions?


Ans:A race condition occurs when two threads access a shared variable at the same time.
The value of the thread that writes its value last is preserved, because the thread is writing
over the value that the previous thread wrote.

6) What is Deadlocks?

A deadlock occurs when two threads each lock a different variable at the same time and
then try to lock the variable that the other thread already locked. As a result, each thread
stops executing and waits for the other thread to release the variable. Because each thread
is holding the variable that the other thread wants, nothing occurs, and the threads remain
deadlocked.

7) Diff between new operator and operator new?


when you say new(1024), you are using C++ keyword new, which
represents the new operator. The job of new operator is :
1. to allocate the memory
2. to call the constructor.
The (1)st job is done using C++'s inbuilt 'operator new'. (Bad
overloading of terminologies!). The prototype of "operator new" is
void* operator new (size_t);

Thus, In the first example, the new operator expects the 'type' and
not the size, since it also needs to call the constructor on that
type. Hence the first line gives compilation error. (1024 is not a
type.)

On the second line, you are explicitly calling the 'operator new'. In
other words, what you are doing is only the first step (allocating the
memory). The 'operator new' requires size_t which you have provided
properly (1024), and hence the code compiles properly.

Rediff

1) What are the functions provided by Cobject?


Ans: Diagnostic: 1) AssertValid()
2) Dump()
Runtime: 1) IsKindof()
2) GetRuntimeClass()
Serialization 1) IsSerializable()
2) Serialize()

My Stack of Questions:

1) What is the difference between exit(), ExitProcess()?


2) DefWindowProc?
3) What is the diff bet macros and inline function?
4) Diff bet C structure and C++ structure?
5) How to identify end of file?
socket
An object that represents an endpoint for communication between processes
across a network transport. Sockets have a datagram or stream type and can be
bound to a specific network address. Windows Sockets provides an application
programming interface (API) for handling all types of socket connections in
Windows.

Basic concepts
The basic building block for communication is the socket. A socket is an endpoint
of communication to which a
name may be bound. Each socket in use has a type and an associated process.
Sockets exist within
communication domains. A communication domain is an abstraction introduced to
bundle common properties of
threads communicating through sockets. Sockets normally exchange data only
with sockets in the same domain
(it may be possible to cross domain boundaries, but only if some translation
process is performed). The
Windows Sockets facilities support a single communication domain: the Internet
domain, which is used by
processes which communicate using the Internet Protocol Suite

Two types of sockets currently are available to a user. A stream socket provides
for the bi-directional, reliable,
sequenced, and unduplicated flow of data without record boundaries.

A datagram socket supports bi-directional flow of data which is not promised to


be sequenced, reliable, or
unduplicated. That is, a process receiving messages on a datagram socket may find
messages duplicated, and,
possibly, in an order different from the order in which it was sent. An important
characteristic of a datagram
socket is that record boundaries in data are preserved. Datagram sockets closely
model the facilities found in
many contemporary packet switched networks such as Ethernet.

the protocol may be symmetric or asymmetric. In a symmetric protocol, either


side
may play the master or slave roles. In an asymmetric protocol, one side is
immutably recognized as the master,
with the other as the slave.
An example of a symmetric protocol is the TELNET protocol used in the Internet
for
remote terminal emulation. An example of an asymmetric protocol is the Internet
file transfer protocol, FTP. No
matter whether the specific protocol used in obtaining a service is symmetric or
asymmetric, when accessing a
service there is a ``client process'' and a ``server process''.

There are several differences between a datagram socket and a stream socket.
1. Datagrams are unreliable, which means that if a packet of information gets lost
somewhere in the Internet, the sender is not told (and of course the receiver does
not know about the existence of the message). In contrast, with a stream socket,
the underlying TCP protocol will detect that a message was lost because it was
not acknowledged, and it will be retransmitted without the process at either end
knowing about this.
2. Message boundaries are preserved in datagram sockets. If the sender sends a
datagram of 100 bytes, the receiver must read all 100 bytes at once. This can be
contrasted with a stream socket, where if the sender wrote a 100 byte message, the
receiver could read it in two chunks of 50 bytes or 100 chunks of one byte.
3. The communication is done using special system calls sendto() and
receivefrom() rather than the more generic read() and write().
4. There is a lot less overhead associated with a datagram socket because
connections do not need to be established and broken down, and packets do not
need to be acknowledged. This is why datagram sockets are often used when the
service to be provided is short, such as a time-of-day service.

Broadcasting

Broadcast messages can place a high load on a network, since they force every
host on the network to service
them.

Broadcast is typically used for one of two reasons: it is desired to find a


resource on a local network without prior knowledge of its address, or important
functions such as routing
require that information be sent to all accessible neighbors.

What is the difference between a port and a socket?

I am assuming you are referring to logical uses. A port is a logical connection method
two end points communicate with. Ports operate at the Transport layer of the OSI. For
example a VPN client connects to a VPN server over Port 1723. A socket is one end
point of a connection. Sockets are a means of plugging the application layer in. Sockets
are determined by an IP address and port number. For example, for a VPN client to
connect the client would need to use the socket determined by the port number and IP of
the local client.

Q: 1. can you clarify the difference between a port and a socket?

A: A socket is an operating system abstraction similar to a file descriptor; it is part of the


Application Program Interface (API). A program creates a socket, specifies that it will be
used with TCP/IP, and then fills in details such as whether the socket will be used by a
client or a server.

A port is a transport-layer abstraction that is part of the TCP/IP suite. Each port is a 16-bit
integer; the space of ports for TCP and UDP are separate. Ports used by servers are given
reserved values (e.g., a Web server uses port number 80).

Note that after creating a socket, a program specifies a port to be used with that socket.

Q: 2. also when can two processes end up sharing the same port (except the case when
forking is done after binding to a port then parent-child share it).

Yes, two processes can share the same port. Sharing is most common in TCP because
TCP identifies a connection by 4 items:

 Client IP address
 Client port number
 Server IP address
 Server port number

Thus, two processes can provide Web service on port 80 concurrently as long as the two
TCP connections go to different clients.

Concurrent, connection oriented servers The typical server in the Internet domain
creates a stream socket and forks off a process to handle each new connection that it
receives. This model is appropriate for services which will do a good deal of reading and
writing over an extended period of time, such as a telnet server or an ftp server. This
model has relatively high overhead, because forking off a new process is a time
consuming operation, and because a stream socket which uses the TCP protocol has high
kernel overhead, not only in establishing the connection but also in transmitting
information. However, once the connection has been established, data transmission is
reliable in both directions.

Iterative, connectionless servers Servers which provide only a single message to the
client often do not involve forking, and often use a datagram socket rather than a stream
socket. Examples include a finger daemon or a timeofday server or an echo server (a
server which merely echoes a message sent by the client). These servers handle each
message as it receives them in the same process. There is much less overhead with this
type of server, but the communication is unreliable. A request or a reply may get lost in
the Internet, and there is no built-in mechanism to detect and handle this.

Single Process concurrent servers A server which needs the capability of handling
several clients simultaneous, but where each connection is I/O dominated (i.e. the server
spends most of its time blocked waiting for a message from the client) is a candidate for a
single process, concurrent server. In this model, one process maintains a number of open
connections, and listens at each for a message. Whenever it gets a message from a client,
it replies quickly and then listens for the next one. This type of service can be done with
the select system call.

Functions Library
ntohl
The Windows Sockets ntohl function converts a u_long from TCP/IP network order to
host byte order (which is little-endian on Intel processors).

Htonl
The Windows Sockets htonl function converts a u_long from host to TCP/IP network
byte order (which is big-endian).

The System and the Timer

The Windows timer is a relatively simple extension of the timer logic built into the PC's
hardware and the ROM BIOS. Back in the pre-Windows days of MS-DOS programming,
an application could implement a clock or a timer by trapping a BIOS interrupt called the
"timer tick." This interrupt occurred every 54.925 msec, or about 18.2 times per second.
This is the original 4.772720 MHz microprocessor clock of the original IBM PC divided
by 218.
Writing a bitmap to a BMP file is fairly simple if we have a handle to device-independent bitmap. We simply
write BITMAPINFOHEADER information followed by the contents of the bitmap. The three fields that we
have to set in the BITMAPINFOHEADER are the bfType which should always be "BM", the bfSize which is
the size of the bitmap including the infoheader and the bfOffBits which is the offset to the bitmap bits from
the start of the file.

If you have a device-dependent bitmap to begin with, you have to first create a DIB from it. Creating a DIB
from a DDB has already been covered in another section.

// WriteDIB - Writes a DIB to file


// Returns - TRUE on success
// szFile - Name of file to write to
// hDIB - Handle of the DIB
BOOL WriteDIB( LPTSTR szFile, HANDLE hDIB)
{
BITMAPFILEHEADER hdr;
LPBITMAPINFOHEADER lpbi;

if (!hDIB)
return FALSE;

CFile file;
if( !file.Open( szFile, CFile::modeWrite|CFile::modeCreate) )
return FALSE;

lpbi = (LPBITMAPINFOHEADER)hDIB;

int nColors = 1 << lpbi->biBitCount;

// Fill in the fields of the file header


hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always
"BM"
hdr.bfSize = GlobalSize (hDIB) + sizeof( hdr );
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;
hdr.bfOffBits = (DWORD) (sizeof( hdr ) + lpbi->biSize +
nColors * sizeof(RGBQUAD));

// Write the file header


file.Write( &hdr, sizeof(hdr) );

// Write the DIB header and the bits


file.Write( lpbi, GlobalSize(hDIB) );

return TRUE;
}

reversing bits
int IntReverse(int src)
{
int ret = 0;
int bitPos;

for (bitPos = 0; bitPos < sizeof(int) * 8; bitPos++)


ret |= ((((1 << bitPos) & src) ? 1 : 0) << (sizeof(int) * 8 - bitPos)) & 1 << (sizeof(int) * 8 - bitPos);
return ret;
}

typedef
typedef type-declaration synonym;

The typedef keyword defines a synonym for the specified type-declaration. The
identifier in the type-declaration becomes another name for the type, instead of naming
an instance of the type. You cannot use the typedef specifier inside a function definition.

In contrast to the class, struct, union, and enum declarations, typedef declarations do
not introduce new types — they introduce new names for existing types.

Example

// Example of the typedef keyword


typedef unsigned long ulong;

ulong ul; // Equivalent to "unsigned long ul;"

typedef struct mystructtag


{
int i;
float f;
char c;
} mystruct;

mystruct ms; // Equivalent to "struct mystructtag ms;"

typedef int (*funcptr)(); // funcptr is synonym for "pointer


// to function returning int"

funcptr table[10]; // Equivalent to "int (*table[10])();"

1MB=1024KB
1024MB=1GB
Data Measurement Chart
Data Measurement Size
Bit Single Binary Digit (1 or 0)
Byte 8 bits
Kilobyte (KB) 1,024 Bytes
Megabyte (MB) 1,024 Kilobytes
Gigabyte (GB) 1,024 Megabytes
Terabyte (TB) 1,024 Gigabytes
Petabyte (PB) 1,024 Terabytes
Exabyte (EB) 1,024 Petabytes

OLE
Object Linking and Embedding. A technology for transferring and sharing
information among applications. When an object, such as an image file created
with a painting application, is linked to a compound document, such as a
spreadsheet or a document created with a word processing application, the
document contains only a reference to the object; any changes made to the
contents of a linked object are seen in the compound document. When an object is
embedded in a compound document, the document contains a copy of the object;
any changes made to the contents of the original object are not seen in the
compound document unless the embedded object is updated. See also
Automation.

The OLE classes work with the other application framework classes to provide easy
access to the ActiveX API, giving your programs an easy way to provide the power of
ActiveX to your users. Using ActiveX, you can:

 Create compound documents, which allow users to create and edit documents
containing data created by multiple applications, including text, graphics,
spreadsheets, sound, or other types of data.

 Create OLE objects that can be embedded in compound documents.


 Use OLE drag and drop to copy data between applications.
 Use Automation to control one program with another.
 Create ActiveX controls and ActiveX control containers (formerly called OLE
controls and OLE control containers, respectively).

Questions and Answers


What are the two types of events generated by ActiveX
controls?
1.Stock events
2.Custom Events

What is an ActiveX interface?


An ActiveX interface is a group of related functions that
are grouped together

What is an ActiveX method?


A method is an exposed function that can be applied to a
control via the IDispatch interface.

What Is an OLE Custom Control?


We can customize these objects by saving into image

What are the properties exposed by ActiveX controls?


ActiveX controls have four types of properties:
l Stock:-> These are standard properties supplied to every
control, such as font or
color. The developer must activate stock properties, but
there is little or no
coding involved.

2 Ambient:-> These are properties of the environment that


surrounds the control -
properties of the container into which it has been placed.
These can't be changed,
but the control can use them to adjust its own properties.
For example, it can set
the control's background color to match the container's
background color.

3 Extended:-> These are properties that the container


handles, usually involving size
and placement onscreen.

4 Custom:-> These are properties added by the control


developer.

What Does the Logo Mean?


This comes at the comiplization time, If we give the LOGO
option to the compiler, it take a bitmap file (i.e, ) as
logo before loading the Application

What are some other development tools that support creating


and using ActiveX controls?
1.MFC activex controls using Visual Studio
2.COM acitvex controls using Visual Studio
1. MFC
2. ATL
3. C++
4. VB

Uses for Sockets

Sockets are highly useful in at least three communications contexts:


 Client/Server models

 Peer-to-peer scenarios, such as chat applications


 Making remote procedure calls (RPC) by having the receiving application
interpret a message as a function call

INI file Concept:

What Is an .INI File?

.INI files are plain-text files that contain configuration information. These files are used
by Windows and Windows-based applications to save information about your preferences
and operating environment. "INI" stands for initialization.

Format of .INI Files

.INI files contain one or more sections. Each section begins with a section name, which is
followed by zero or more entries. An entry associates a keyname with avalue. The general
format is:

[section]
keyname=value

Comments can also be included in the file by prefacing the comment with a semicolon
(;).

Windows and Windows for Workgroups use several standard .INI files for storing
configuration information. These files are WIN.INI, SYSTEM.INI, PROTOCOL.INI,
PROGMAN.INI, CONTROL.INI, WINFILE.INI, MSMAIL.INI, SHARED.INI, and
SCHDPLUS.INI. Windows-based programs may also add sections and entries to
WIN.INI, and they may add .INI files in the Windows directory.

Editing .INI Files

Because .INI files use only plain text, they can be edited using any text editor or word
processor. .INI Master also has a built-in text editor for making corrections in the .INI
files you are diagnosing.
Heap VS Data segment
VS Stack
When a program is loaded into memory, it is organized into three areas
of memory, called segments: the text segment, stack segment, and heap
segment. The text segment (sometimes also called the code segment) is
where the compiled code of the program itself resides.

The remaining two areas of system memory is where storage may be


allocated by the compiler for data storage. The stack is where memory is
allocated for automatic variables within functions. A stack is a Last In
First Out (LIFO) storage device where new storage is allocated and
deallocated at only one `end', called the Top of the stack.

When a program begins executing in the function main(), space is


allocated on the stack for all variables declared within main(). If
main() calls a function, func1(), additional storage is allocated for
the variables in func1() at the top of the stack .When func1() returns,
storage for its local variables is deallocated, and the Top of the stack
returns to to position shown in Figure 14.13(c). If main() were to call
another function, storage would be allocated for that function at the
Top. As can be seen, the memory allocated in the stack area is used and
reused during program execution. It should be clear that memory
allocated in this area will contain garbage values left over from
previous usage.

The heap segment provides more stable storage of data for a program;
memory allocated in the heap remains in existence for the duration of a
program. Therefore, global variables (storage class external), and
static variables are allocated on the heap. The memory allocated in the
heap area, if initialized to zero at program start, remains zero until
the program makes use of it. Thus, the heap area need not contain
garbage.

Assignment Suppression Operator?


#include

int main()
{
int a=0,b=0;
printf("Enter two numbers:\n");
scanf("%d %^d",&a,&b);
printf("The numbers are : %d, %d\n",a,b);

return 0;
}

When you execute this program it would ask the user to enter two numbers.
But actually it assigns the value only to the integer variable a but not to
b.

Here the operator '%^' will act as assignment suppression operator and
suppress any assignments to the variable b.
How many max drives can be on machine?
Ans: There can be 26 drives only, but 2 drives are for Floppy disk and rest we
can be assigned to 24 partition.

You might also like