NCTU
, Unix Programming
while user open a file, kernel then handle a table called file descriptor table which store the opened file information(i.e., a pointer to the file), and the table index is file descriptor.
So, the file descriptor is a non negative integer.
0 stdin
1 stdout
2 stderr
in the third command, the second cat
command's stdin is replace by the first command cat /etc/passwd
's stdout by an interface pipe.
The file system will create a data block ( usually is 4KB
) to store the first 10 bytes
, after the lseek
operation, system find that the first data block is not enough to store, so it will create the other block which locate between the first block is 16KB
, so the file.hole
file actually store 8KB
on the system. But the cp
command need to parse a file until an EOF
, so it will parse totally 20KB
and create file.nohole
.
buff size choose = 4KB
( equivalent to kernel block size )
'\n'
)we could set buffer mode by C library
void setbuf(FILE *fp, char *buf)
int setvbuf(FILE *fp, char *buf, int mode, size_t size)
Buffering mode
_IOFBF
: fully buffered_IOLBF
: line buffered_IONBF
: unbufferedWhen the first time call puts
, we would reach the <puts@plt>
at line 3
to check whether the shared library is linked, but how to check?
The line 3
would jump to the puts's GOT
which offset is 0x555555755008
and the value of this offset is an address. If the address is the next instruction of <puts@plt>
( i.e., <puts@plt+6>
), then will jump to <puts@plt+6>
, and goto the next instruction ( i.e., <puts@plt+11>
) which is reslover to update the GOT's value which is the address of puts
.
So that we could goto the puts
library without running resolver again after the first calling of puts
, since the puts's GOT
is updated from the address of <puts@plt+6>
to the address of puts
by resolver.
The first call:`
The second call:
The figures are captured from the ppt of Advanced Programming Environment in the UNIX Environment at NCTU
Only one interface:
ptrace full request-list is in the manual page.
PTRACE_ATTACH
ptrace(PTRACE_ATTACH)
orptrace(PTRACE_TRACEME)
cmd
, a SIGSTOP
signal is sent to the tracee.
waitpid()
to wait for the child processWIFSTOPPED()