fbpx

Unix Linux interview questions on C++ system call, fork, child process,

(Last Updated On: May 12, 2010)

Linux System call:
What’s the difference between system calls and library functions?
there is a context switch associated with a system call
This is not related to C++ or any language.
Libraries are utility functions – written once and used by many applications.
System calls are calls into operating system to perform functions that only an OS can do.
Certain library functions, like printf(), end up calling a system functions to send the buffer to the output device.

how is a system call executed.. when the API resides in the user space how are u still able to

whenever an API is called from User mode that would require a service from an underlying kernel module, the system traps to kernel mode to execute the requested service.
the system calls transfers the control from user program mode which is of low privilege to kernel mode ( high privilege )
what does fork do, can the child process use the fd’s immediately
fork copies the snapshot of the process. The special case of fd’s, kernel makes sure these are properly duplicated and available for child process immediately
different between exec and fork. will parent process and child process
in deadlock if parent is using resource and child will also get same resource ?
what if parent contains two threads ? will child also get 2 threads ? how fork will be thread safe ?
Performance:

class A{ int i;
public:
A(int j):i(j){}
};
class B{int i;
public:
B(int j){i=j;}
};
Which one is faster..uisng the initializer list or initializing in the c’tor body….
Is there any other diff or both will have same performance…??
using the initializer list is faster. can be optimized by the compiler better I believe

Not exactly sure of the performance impact by using member initalizer syntax for built in data types. But in the case of Objects(i mean composition.. i composed in the class), the first one is faster, since, in case 1, the object is created by invoking the copy constructor where as in case 2, the object i is initially created using the default constructor, then initialised using the copy constructor.

For built in data types, something like this
int i
i =j

int i=j

For objects.
Object i(j)

Object i;
i=j;

Dude, they generate _identical_ code on every C++ compiler I have access to. Don’t make the mistake of confusing semantics with implementation.

Really!! I think initializer list uses copy constructor and call to assignment operator will be used in class B….
Please correct me If I am wrong…..

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!
Don't miss out!
Get my TRADE LIKE A BOSS 2 PDF Books

You will received instantly the download links.

Invalid email address
Give it a try. You can unsubscribe at any time.

NOTE!

Check NEW site on stock forex and ETF analysis and automation

Scroll to Top