3

Getting the Resident Set Size is straightforward (getrusage() or /proc/self/statm), but how do I get the amount of swap? From man 5 proc about /proc/self/stat:

nswap %lu   Number of pages swapped (not maintained).

cnswap %lu  Cumulative nswap for child processes (not maintained).

Any other thoughts?

Martin C. Martin
  • 3,565
  • 3
  • 29
  • 36
  • possible duplicate of [how to find out which processes are swapping in linux?](http://stackoverflow.com/questions/479953/how-to-find-out-which-processes-are-swapping-in-linux) – hek2mgl May 24 '13 at 14:12
  • @hek2mgl This is not duplicate at all. The other question is asking about how to get a list of processes that use swap. This question is about how, as a developer, you can check swap usage by your program from inside the code. – Aleks G May 24 '13 at 14:20
  • @AleksG Read the answers. It took me 2 seconds to google this – hek2mgl May 24 '13 at 14:23
  • @hek2mgl I have. None of them is related to this question. – Aleks G May 24 '13 at 14:24
  • `It is not possible to get the exact size of used swap space of a process. Top fakes this information by making SWAP = VIRT - RES, but that is not a good ....` is not related to this question? – hek2mgl May 24 '13 at 14:25

1 Answers1

2

Check if you have VmSwap in /proc/$PROCESS/status. For example: grep VmSwap /proc/1/status

Chris
  • 1,410
  • 12
  • 21