I did an strace on the "ls" command in FC17 Linux.
Following was the output.
execve("/usr/bin/ls", ["ls"], [/* 48 vars */]) = 0
brk(0) = 0x27c1000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc765fa6000
...
I am not getting the purpose and result of passing -1 as the file descriptor to the mmap call, can some one shed some light on this ?
There are two kinds of mappings (areas of virtual memory mapped to a process): file-backed mappings, and anonymous (non file-backed) mappings. There are two ways to request an anonymous mapping:
MAP_ANONYMOUS
(formerly MAP_ANON
) to mmap()
. There is no associated file, so you should pass -1 as file
parameter. Some OSes ignore the file
parameter, others require it to be -1 (BSD IIRC)./dev/zero
. In this case, file
is obviously meaningful.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With