-1

If you had to programmatically have system create swap files for you, how would you do it?

I am not looking to actually create swap file, but am debugging an issue in own code trying to better understand what did i do wrong that would cause system to create the swap files.

My program (as no doubt you have guessed) is doing a lot of reading and writing of files (extract some data from file A and write it to file B)

What would cause something like this to happen?

UPDATE:

  • Please note swap files created are 0 bytes in size.
  • Program is written in Java and runs on Linux
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
  • I just realized my answer relied on a lot of assumptions. Please edit your question to, at minimum refer to the programming language of your program. Secondly, (I'm not sure if it's relevant), you might want to refer to the operating system, just in case that matters. – JayC Dec 29 '11 at 18:45
  • Secondly, it's possible some SDK involved is making the swp files. Again, not sure that matters, but it might. – JayC Dec 29 '11 at 18:47
  • Well, if you want to fill a lot of RAM and get into swapping territory… `perl -e 'while (fork) { open IN, "/dev/urandom"; while ($x .= ) { $x .= $x; } }` On a Fedora system, that'll (hopefully) hit your per-user resource limits before it actually fork-bombs you to death, but it's going to slowly expand to fill all available RAM… – BRPocock Dec 29 '11 at 19:30

3 Answers3

0

Vim or Gvim creates .swp files. Maybe you have a script that invokes Vim? I've never invoked vim in a script, but this is a question about doing that, so I'm pretty sure it's possible.

Community
  • 1
  • 1
JayC
  • 7,053
  • 2
  • 25
  • 41
0

Swap files are for those times when programs use more memory than is available in RAM. To make the system write to swap you just have to use up a lot of memory. You could do that by allocating a lot of blocks of memory.

Bzzt
  • 1,064
  • 8
  • 13
0

As it turns out, the problem came about due to me improperly closing IO connections once files has been read/ written to.

Once i

finally {
    try {
        in.close();
        fstream.close();
        br.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Swap files stopped being created and issue was resolved.

Walery Strauch
  • 6,792
  • 8
  • 50
  • 57
James Raitsev
  • 92,517
  • 154
  • 335
  • 470