How to verify which index of a global array was accessed from another program? - arrays

There is program running which has globally initialized large arrays. I want to verify which index of that large array is getting accessed from another program running in the same machine simultaneously.
I saw how to get a set of pages in the physical memory for a given process proc_id and I also saw how the physical memory of system can be accessed directly. But how to verify which block is getting accessed currently.
How to access the global data segment access pattern of another process is the question. If anyone can direct me to any code example or any api that has this functionality it would be helpful.

Related

why OS create the virtual memory for running process

when a program started the OS will create a virtual memory, which divided into stack, heap, data, text to run a process on it.I know that each segment is used for specification purpose such as text saves the binary code of program, data saves static and global variable. My question is why the OS need to create the virtual memory and divide it into the segments ? How about if OS just use the physical memory and the process run directly on the physical memory. I think maybe the answer is related with running many process at the same time, sharing memory between process but i am not sure. It is kind if you give me an example about the benefit of creating virtual memory and dividing it into the segments.
In an environment with memory protection via a memory mapping unit, all memory is virtual (mapped via the MMU). It's possible to simply map each virtual address linearly to physical addresses, while still using the protection capabilities of the MMU, but doing that makes no sense. There are many reasons to prefer that memory not be directly mappped, such as being able to share program instructions and shared library code between instances of the same program or different programs, being able to fork, etc.

How can I restrict the number of instances of my C program?

Title says it all, I need to only allow one instance of my C program to be run. How can I accomplish this?
You can use shared memory for this purpose. Shared memory is an OS-level mechanism.
Start instance #1 of your app
The app checks the shared memory if there is a value stored
If not, the app stores some value into the shared memory.
Start instance #2 of your app
The app checks the shared memory if there is a value stored
The app sees there's already a shared memory value with a value and kills itself
You can use the shared memory to store the specific number of instances your app is allowed to run.

Where to store data to be used by all processes?

I am trying several projects in editing a Linux kernel.
One of the projects is to write a system call function that will receive a name of a program and not allow that program to be run through execv (note, several programs can be blocked - we need a list of blocked programs).
I have figured out what to do for most of the exercise. For example, one challenge is to log all attempts of a certain process to execute any of the blocked programs - I decided to store this in the heap of the process using kmalloc().
However, I am debating where to store the "list of blocked programs" - no matter which process is running, when in execv we must have access to this list. Would it make sense then to store this list inside the heap of the init process or is there some "general" memory location that is shared between all processes (never heard of one before but I was wondering if there might be one).
If the answer is indeed inside the heap of init, how do I allocate memory there from whichever process is currently running?

Can I influence the address malloc returns on Linux?

I am currently trying to find a way to only get return addresses in a specific 1GB range using malloc under linux.
Is there a way to either tell the kernel what (virtual) addresses to use or to know for a process which addresses can be returned?
I am running a 32bit Linux on an ARM based system (SoC).
I read about page directories. Could they be a way to solve this, for example by making only one or two page directories available to the process?

Can I check for disk access at runtime?

I'm running some very specialized experiments for a research project. These experiments call for controlling memory accesses: my application should not, under any circumstances, swap information with the disk. That is, all information the application needs must stay in RAM for the duration of the execution, but it should use as much RAM as possible.
My question is: is there any way I can control disk access by my application, or at least count disk accesses for later analysis?
This is using C and Linux.
Please let me know if I can clarify the question... been working on this for so long I think everybody knows exactly what I'm talking about.
One thing you can do is actually create a ramfs or RAM file system. Are you working on a unix platform? If so you can check out mount and umount on how to create them.
http://linux.die.net/man/8/mount
http://linux.die.net/man/8/umount
Basically what you do is you create a file system stored in your RAM. You don't have to deal with all the disk read/write time anymore. If i read your question correctly you want to try avoiding disk access if you can. It's very simple to do really since you can have multiple file systems located on both a hard drive and memory.
http://www.cyberciti.biz/faq/howto-create-linux-ram-disk-filesystem/
http://www.alper.net/linuxunix/linux-ram-based-filesystem/
Hope this all helped.
The mlock system call allows you to lock part or all of your process's virtual memory to RAM, thus preventing it from being written to swap space. Notice that another process with root priviledges can still that memory area.

Resources