LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I (sometimes) cant write my program file when a copy of it is running (https://www.linuxquestions.org/questions/linux-newbie-8/i-sometimes-cant-write-my-program-file-when-a-copy-of-it-is-running-683227/)

foof 11-13-2008 02:49 PM

I (sometimes) cant write my program file when a copy of it is running
 
Can anyone answer this?

If I write a small program and run it, and while it is running, I try to rebuild (or in any way modify the program file), on Linux, I am (sometimes) not allowed to write to the file. Why?

It has something to do with memory management.

pixellany 11-13-2008 03:04 PM

welcome to LQ!!

In general, you cannot write to a file when it is in use. I would assume that includes a file which is a program. I don't think this is memory management--I think it is the filesystem.

Tell us more about the program--what it does, what language, etc.---and what exactly happens when you try to do something.

foof 11-13-2008 03:14 PM

Actually it is question in an operating system course I am taking. We are currently studying memory management. That is why I know the answer has to do with memory management. I have search the text and internet and have not found any info that touches on this. I don't have access to Linux source as of this moment so I figure I'd put the question out the people with Linux experience.

pixellany 11-13-2008 03:20 PM

Thank you for acknowledging that this is homework...

But now I am really confused as to what the question is. It now appears you are asking something purely hypothetical. If the question in fact relates to not being able to write to a file that is in use, I can't see how that is a memory management issue.

foof 11-13-2008 04:00 PM

The question is not hypothetical as the instructor showed an example of it in class.
I think it has to do with the fact that when you change a program and recompile you change the virtual address space of the executable image. Since the text segment (shareable in Linux) is already in physical memory and being used by the copies already running, if the new version were to be run, it would be run with the old text segment. Something along those lines although I dont know, the reason for the question.

pixellany 11-13-2008 04:08 PM

My take is that you do not understand the question. That being the case, how can we help with the answer?

You talk about compiling and running. When you run a binary (compiled program) it loads itself into memory**. When you quit, it frees the memory---the next time you run it, it could easily go somewhere else. In this context, what do you mean by the "text segment"?

**A complex program would load PART into memory.

foof 11-13-2008 04:17 PM

You maybe right, I might not understand the question. I will have to verify it with the instructor. Thanks for your patience and help.


All times are GMT -5. The time now is 12:19 AM.