Life is full of questions and answers...

Linux, Networking, C and C++ questions some of them have answers too!

 

1. What do you mean by bus error ?

2. What do you mean by return address which gets pushed on to the stack when a procedure is called ?

3. My bind(...) is failing on IP address which is used in some other bind though I've set SO_REUSED option using setsockopt(...). what could be the reason ?

4. What exactly %ds used in printf do ?

5. What do major and minor numbers of a perticular device signify ? what are their lengths in 2.4 and 2.6 kernels.

6. What's O(1) scheduler in 2.6. any one of its advantages...

7. WAP to find out the endianness of the machine you are working on.

8. suppose I want to create a file and read/write on that.

    I say,
    creat("/home/vishwa/file1", S_IRWXU);
   
    then I would like to read and write. Do I need to open it for reading ?
    Does open succeed just after creat ? if it's not so, how can I read from the file ?
 
9.
I've several threads t1, t2, t3 running in a given process P let's say.
 
I'll call fork() from t3. what would happen ? Does it copy all the threads in the parent process P or only the calling thread becomes a main thread in the child process.
What about mutexes(pthread_mutexes) and signal dispositions which were being used by the calling thread / process.

 

10.

In Binary search we always calculate the position of mid element as mid = (low + high ) / 2, but for large values of low and high, (low+high) could go out of bounds.
Specifically, it fails if the sum of low and high is greater than the maximum positive int value (231 - 1). The sum overflows to a negative value, and the value stays negative when divided by two. In C this causes an array index out of bounds with unpredictable results. In Java, it throws ArrayIndexOutOfBoundsException. what is the remedy for this ?
 
11. Which is better a long nested if-else stmts or switch stmts for comparing constants(since switch is limited in this case)  ?
 
12. How to set first 'n' number of bits in a 32 bit variable (very optimized soln) ?