0

I've got a general question and I don't really find a correct explanation.

I have a program which is creating big files in /tmp/;

Theses files are created as follow :

 FILE *tmp;
 tmp = fopen(argv[i-1]+3, "w");

And I've got another program, checking all the executable and killing all the process which are using too much memory.

My question is as follow:

Is the first program in danger ? or writing in /tmp/ is considered a disk space used and not memory used ?

Thanks in advance for your answer,

Best Regards.

Valentin Montmirail
  • 2,594
  • 1
  • 25
  • 53
  • 5
    StackOverflow is explicitly for questions about writing software. This might be a better question for http://unix.stackexchange.com/. – Charles Duffy Jan 19 '16 at 15:20
  • Do you want to know if files in `/tmp` are stored on RAM? Or do you want to know if the size of used files in `/tmp` is added to statistics about memory usage (assuming `/tmp` is in RAM)? – JojOatXGME Jan 19 '16 at 15:25
  • ...and for the latter, it depends very specifically *which* statistics are in use, and *how*, specifically, those files are being accessed -- if the measure is virtual memory and they're `mmap`'d it's a different answer from content generated with normal writes. – Charles Duffy Jan 19 '16 at 15:26
  • I want to know if the size used by files in /tmp will be detected by the 2nd software and considered as memory use. – Valentin Montmirail Jan 19 '16 at 15:26
  • @ValentinMontmirail, ...see my comment -- whether they'll be detected as memory usage depends on details you haven't provided. In general, however, the answer is "no". – Charles Duffy Jan 19 '16 at 15:27
  • There are not `mmap`, basically I'm just redirecting some output into a file in /tmp/ (to have right to write) but I could have redirect anywhere. It's a really simple `fopen()`, `fprintf`, `fclose`. – Valentin Montmirail Jan 19 '16 at 15:28
  • 3
    Won't be detected, then. – Charles Duffy Jan 19 '16 at 15:29
  • @ValentinMontmirail I thing when you are accessing the files using `fopen`, it will not count for the second application. But I do no really know it. It is just my intension since you can not access the data just like accessing the memory (it is not mapped in memory). – JojOatXGME Jan 19 '16 at 15:30
  • I think your topic/header provides some misconception. Maybe this is the reason why the question is "on hold" now. – JojOatXGME Jan 19 '16 at 15:49

1 Answers1

2

It depends on which type of file system (or "implementation of how the files are stored") /tmp uses. It may be on disk, or in memory.

Check in the file /etc/fstab. If you have a line like this, with tmpfs, /tmp will be in main memory:

none /tmp tmpfs defaults 0 0
Thomas Padron-McCarthy
  • 27,232
  • 8
  • 51
  • 75
  • https://en.wikipedia.org/wiki/Tmpfs – JimmyB Jan 19 '16 at 15:21
  • 2
    Actually -- the OP is asking not just if writing to /tmp uses RAM, but if writing to /tmp risks being killed by software monitoring memory usage. That's a different question, with a different answer: Even if `/tmp` *is* a tmpfs mount, most tools attempting to kill software allocating excessive memory won't recognize its usage as such (unless they're measuring virtual memory usage and the files in `/tmp` are mmap'd). – Charles Duffy Jan 19 '16 at 15:22