50% found this document useful (2 votes)
456 views10 pages

Informations Some Interfaces of Proc Filesystem. Is There Any Other Ways To Get Process Memory Informations Apart From Proc Interfaces?

The document discusses several topics related to Linux kernel programming: 1. Linux security modules allow security extensions to be plugged into the kernel like SELinux, AppArmor, Smack, and Tomoyo. 2. The mm_struct memory descriptor within a process's task_structure can be used to get memory information for a specific process, in addition to using proc filesystem interfaces. 3. Interrupt service routines must be short, non-blocking, and use proper locking to handle hardware interrupts and pass requests to the CPU.

Uploaded by

kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
456 views10 pages

Informations Some Interfaces of Proc Filesystem. Is There Any Other Ways To Get Process Memory Informations Apart From Proc Interfaces?

The document discusses several topics related to Linux kernel programming: 1. Linux security modules allow security extensions to be plugged into the kernel like SELinux, AppArmor, Smack, and Tomoyo. 2. The mm_struct memory descriptor within a process's task_structure can be used to get memory information for a specific process, in addition to using proc filesystem interfaces. 3. Interrupt service routines must be short, non-blocking, and use proper locking to handle hardware interrupts and pass requests to the CPU.

Uploaded by

kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 10

1. What are the Linux security modules and why do we need it in Linux?

Linux security module is a framework which allow for security extensions to be plugged in to the
kernel, has been used to implement mandatory access control in Linux
We have different security modules in linux
Selinux
AppArmor
Smack (Label based MAC)
Tomoyo (Path based MAC)

2. Suppose we have some process running in the user space, we can get its memory
informations some interfaces of proc filesystem. Is there any other ways to get process
memory informations apart from proc interfaces?

We can get the memory informations of any particular process running in linux kernel using
memory descriptor of that process
mm_struct (memory descriptor) will be a part of process task_structure(process descriptor). It will
have all memory informations with respect to that particular process

3. How user space programs communicates with kernel space? How static and dynamic linking with
libc library happens while compiling the normal C program?

4. what is interrupt service routine(ISR)? Name some of the constaints needs to be considered
while writing the interrupt handlers?
An ISR (also called an interrupt handler) is a software process invoked by an interrupt request from
a hardware device. It handles the request and sends it to the CPU, interrupting the active process.
When the ISR is complete, the process is resumed.
We need to consider below constaints while writing the ISR
1. Short CPU hold time
2. It should not sleep
3. We should use proper locking mechanism inside interrupt handler

5. Bottom half mechanisms in linux? How prioriry handling mechanism has incorporated
with those mechanisms
We have different mechanisms for implementing the bottom half mechanisms in linux
a. Softirqs
b. Tasklets
c. Workqueues

Different softirqs in priority order

enum
{
HI_SOFTIRQ=0, /* High Priority */
TIMER_SOFTIRQ,
NET_TX_SOFTIRQ,
NET_RX_SOFTIRQ,
BLOCK_SOFTIRQ,
BLOCK_IOPOLL_SOFTIRQ,
TASKLET_SOFTIRQ,
SCHED_SOFTIRQ,
HRTIMER_SOFTIRQ,
RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */

NR_SOFTIRQS
};

Tasklets are a bottom-half mechanism built on top of softirqs i.e. tasklets are represented by two
softirqs: HI_SOFTIRQ and TASKLET_SOFTIRQ. Tasklets are actually run from a softirq. The
only real difference in these types is that the HI_SOFTIRQ based tasklets run prior to the
TASKLET_SOFTIRQ tasklets. So, tasklet_schedule() basically calls
raise_softirq(TASKLET_SOFTIRQ)

6. User space memory mapping

7.

function prologue and epilogue


Function prologue typically does the following actions if the architecture has a base pointer (also
known as frame pointer) and a stack pointer:
• Pushes current base pointer onto the stack, so it can be restored later.
• Assigns the value of stack pointer (which is pointed to the saved base pointer) to base
pointer so that a new stack frame will be created on top of the old stack frame.
• Moves the stack pointer further by decreasing or increasing its value, depending on whether
the stack grows down or up. On x86, the stack pointer is decreased to make room for the
function's local variables.
Function epilogue reverses the actions of the function prologue and returns control to the calling
function. It typically does the following actions (this procedure may differ from one architecture to
another):
• Drop the stack pointer to the current base pointer, so room reserved in the prologue for local
variables is freed.
• Pops the base pointer off the stack, so it is restored to its value before the prologue.
• Returns to the calling function, by popping the previous frame's program counter off the
stack and jumping to it.

Difference between General Purpose OS(GPOS) and Real Time Operating Systems(RTOS)?
Volatile keyword in C
Can we use const with volatile in C?
Top Half and Bottom Half Mechanisms?
What are the differences between semaphore and mutex?
Can we use mutexes inside the interrupt handler?
Multithreading debugging using gdb.
Static code analysis tools and tools for memory leak.
What are the synchronization mechanisms in linux?
Message passing techniques in linux.
Multiprocessing and multithreading.
1. Set the bit in memory location" for example if at address 0xffeh2f the 21st bit is 0 then set the 21st bit

3. Difference between process and thread?


 
Process is an executable entity in linux.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 is a lightweight process (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
 
 
5. What is Spinlock and Tasklet in Kernel programming
 
Spinlock is a synchronization premitive.spinlock is a lock which causes a thread trying to acquire it
to simply wait in a loop ("spin") while repeatedly checking if the lock is available. Since the thread
remains active but is not performing a useful task, the use of such a lock is a kind of busy waiting.
Once acquired, spinlocks will usually be held until they are explicitly released, although in some
implementations they may be automatically released if the thread being waited on (that which holds
the lock) blocks, or "goes to sleep"
 
 
where as Tasklet is a one of the mechanism for implementing the bottom half interrupt
handling(deffering mechanism)
 
Tasklets are a deferral scheme that you can schedule for a registered function to run later. The top
half (the interrupt handler) performs a small amount of work, and then schedules the tasklet to
execute later at the bottom half. Tasklets are represented by the tasklet_struct structure , which
includes the necessary data to manage and maintain the tasklet
 

 
 
 
 
 
 
 
 
6. Interrupt handling, top half and bottom half?
 
Interrupt is a hardware signal which interrupts the normal execution flow of the processor, There
will be a atleast one interrupt handler registered with each interrupts in linux. Whenever process
recieves the interrupt from a particular source, it will pause the execution of currently running
process and excecutes the interrupt handler registered with that particular interrupt.
 
In linux, interrupt handling process is divided into two halves
Top half  and bottom half
 
Top half is meant for critical tasks and bottom half is meant for non critical tasks . In the typical
scenario, the top half saves device data to a device-specific buffer, schedules its bottom half, and
exits: this is very fast. The bottom half then performs whatever other work is required, such as
awakening processes, starting up another I/O operation, and so on. This setup permits the top half to
service a new interrupt while the bottom half is still working.
 
The Linux kernel has two different mechanisms that may be used to implement bottom-half
processing
Tasklets and Workqueues
 
 
7.What if kernel memory stack gets overflow?
The Linux kernel stack has a fixed size. There is no mechanism to prevent the kernel from
overflowing the stack.
An overflow in kernel stack is a common bug in the Linux operating system. These bugs are
difficult to detect because they are created as a side effect of the code and not as an inherent mistake
in the algorithm implementation.
 
 
8. Kernel Synchronization
In a shared memory environment, developer must ensure that shared resources are protected from
concurrent process. The kernel is no exception. Shared resources require protection from concurrent
access because if multiple threads of execution access and manipulate the data at the same time, the
threads may overwrite each other's changes or access data while it is in an inconsistent state. Before
going through the kernel synchronization premitives, we must have a knowledge on what is critical
section in linux kernel?
 
Followings are the different synchronization mechanism provided by linux kernel
1. Atomic operations
2. Spinlocks (reader / writer spinlocks)
3. Mutex
4. Semaphores (reader /writer semaphores) 
5. Completions
 
 
9. Device tree in linux kernel?
 
The core reason for the existence of Device Tree in Linux is to provide a way to describe non-
discoverable hardware. This information was previously hard coded in source code.
Device Tree data can be represented in several different formats. It is derived from the device tree
format used by Open Firmware to encapsulate platform information. The device tree data is
typically created and maintained in a human readable format in .dts source files and .dtsi source
include files.
The device tree source is compiled into a binary format contained in a .dtb blob file. The format of
the data in the .dtb blob file is commonly referred to as a Flattened Device Tree (FDT). The Linux
operating system uses the device tree data to find and register the devices in the system.
 
The Flattened Device Tree (FDT) is a data structure. Nothing more.
It describes a machine hardware configuration. It is derived from the device tree format used by
Open Firmware. The format is expressive and able to describe most board design aspects including:
     the number and type of CPUs
     base addresses and size of RAM
     busses and bridges
     peripheral device connections
     interrupt controllers and IRQ line connections
     pin multiplexing
#include "pxa910.dtsi"
/ {
    compatible = "mrvl,pxa910-dkb", "mrvl,pxa910";
    chosen {
        bootargs = "<boot args here>";
    };
    memory {
        reg = <0x00000000 0x10000000>;
    };
    soc {
        apb@d4000000 {        
 
            uart1: uart@d4017000 {
            status = "okay";
            };
            twsi1: i2c@d4011000 {
                #address-cells = <1>
                #size-cells = <0>
                status = "okay";
                pmic: 88pm860x@34 {

                    compatible = "marvell,88pm860x";


                    reg = <0x34>;
                    interrupts = <4>;
                    interrupt-parent = <&intc>;
                    interrupt-controller;
                    #interrupt-cells = <1>;

                                                                     }
                                                                   }
               }
 
10. handling OOPS and Kernel_panic messages
http://opensourceforu.com/2011/01/understanding-a-kernel-oops/
https://sanjeevsharmaengg.wordpress.com/2014/06/23/debugging-analysis-of-kernel-panics-
and-kernel-oopses-using-system-map/

1. WAP to swap two integer numbers without using third variable.


X= x ^ y
y= x ^ y
x = x^ y

2. WAP to change Uppercase letters to Lowercase letter and viceversa in a given string.
uppercase to lowercase
for(i=0;i<=strlen(str);i++)
{
if(str[i]>=65 && str[i]<=92)
{
str[i]=str[i]+32;
}
}

ASCII value of 'A' is 65 while 'a' is 97. Difference between them is 97 – 65 = 32


So if we will add 32 in the ASCII value of 'A' then it will be 'a' and if will we subtract 32 in ASCII value of
'a' it will be 'A'. It is true for all alphabets

or we can use toupper and tolower library functions

3. WAP to check whether a number is divisible by 4 without using %

4. Write any recursion function.


unsigned long long int factorial(unsigned int i) {

if(i <= 1) {
return 1;
}
return i * factorial(i - 1);
}

int main() {
int i = 12;
printf("Factorial of %d is %d\n", i, factorial(i));
return 0;
}

5. What happens to the following code while executing


int sum(int n){
sum(n-1);
}
It will be resulting in a stack overflow because above recursive function doesn't have
termination condition

6. How much will be increased by incrementing integer pointer and function pointer.
Depnding on the Architecture you are working on. If you working on 32 bit architecture,
incrementing interger pointer will increment the pointer variable by 4 bytes. If you working on 64
bit architecture, incrementing interger pointer will increment the point variable by 8 bytes.
Incremented value of function pointer depending on what type of function pointer we are
incrementing

7. Write function prototype for a function pointer which will return int, and takes char
pointer and int pointer as input.
int (* func_pointer)(char * , int *)

8. What happens to the following code while executing


struct {
int x;
char c;
float f;
}ST;
main(){
ST *tmp = NULL;
tmp->x; // will result in a NULL pointer dereferencing
&(tmp->c);
}
9. What all are stored in stack.
Stack, where automatic variables are stored, along with information that is saved each time a
function is called. Each time a function is called, the address of where to return to and certain
information about the caller’s environment, such as some of the machine registers, are saved on the
stack. The newly called function then allocates room on the stack for its automatic and temporary
variables. This is how recursive functions in C can work. Each time a recursive function calls itself,
a new stack frame is used, so one set of variables doesn’t interfere with the variables from another
instance of the function

10. Storage classes.Who intializes the static variables with intial value 0.
Storage class specifiers in C
auto
11. register
12. extern
13. static
14. typedef
It will be intialized to zero. The initialization is performed only once at the
time of memory allocation by the compiler

15. UserSpace memory mapping.

16. Synchronization primitives


I have already included the answer for this question in my previous doc shared

17. How to distinguish whether to use semaphore or mutex for a given use case.
Use a semaphore when you (thread) want to sleep till some other thread tells you to wake up.
Semaphore 'down' happens in one thread (producer) and semaphore 'up' (for same semaphore)
happens in another thread (consumer) e.g.: In producer-consumer problem, producer wants to sleep
till at least one buffer slot is empty - only the consumer thread can tell when a buffer slot is empty.

Use a mutex when you (thread) want to execute code that should not be executed by any
other thread at the same time. Mutex 'down' happens in one thread and mutex 'up' must
happen in the same thread later on

#include <stdio.h>

int factorial(int);

int main()
{
int num;
int result;
printf("Enter a number to find it's Factorial: ");
scanf("%d", &num);
if (num < 0)
{
printf("Factorial of negative number not possible\n");
}
else
{
result = factorial(num);
printf("The Factorial of %d is %d.\n", num, result);
}
return 0;
}
int factorial(int num)
{
if (num == 0 || num == 1)
{
return 1;
}
else
{
return(num * factorial(num - 1));
}
}

1. how much size will allocate in stack if above factorial function called first time.

2. In above factorial function if i remove if else conditions what will happen.

3. In interrupt handler if we increase the code size what will happen.

4. in a process suppose three threads are running, if one thread is crashed the remaing two
threads won't have any dependency on crashed thread then what will happen.

5. Synchronization mechanisum questions on mutex,semaphore.

6. int *(*fp) (char *,int); if i increase this function pointer how much size it will increase.

7. if we increase the char pointer and int pointer then how much size will increased.

8. how do you debugg if any crash happens in user space or kernel space.

9. how many cpu registers are their in your project board architecture.

18. Given an 32 bit integer write a code to set the 21st bit of an integer using pointer given an
void pointer as a function argument to set the 21st bit.

19. 1. Regarding ptrs, 


20. if int *ptr is provided, find the 5th byte using it.
21. int ptr is provided, set 4th byte's 5th bit. 
22. 2. bootsequence
23. 3. Regarding dynamic library linking. 
1.

1. Write a funcion in c that takes 2 args, 1 int * ptr and 1 offset n and sets nth byte in ptr, will this code work
on both little and big endian machines
2. Write a funcion in c that takes 3 args, 1 int * ptr and 1 offset n and 1 bit num m and sets mth bit in nth
byte in ptr
3. how to use memcpy to copy 1 array to other in such a way that target array has reversed data as
compared to source array
4. Write a program to reverse an arry elements
5. What is DMA and what all to take care to avoid problems of having old data in cache and memory
6. how to achieve synchronisation between 2 processes
7. how to achieve synchronisation between 1 process and ISR
8. How to access same kernel memory from 2 user space process
9. How to write SPI driver in user space
10. how to communicate between user and kernel space
11. previous projects
12. how to map physical address to virtual address in Linux and vice versa
13. where are formal argumens of a function stored
14. can we store some variable in registers
15. if we do malloc, where is this data stored
16. Linux device driver overview

You might also like