首页 > 试题广场 >

回答问题

[问答题]

A program named mycat.c is given out as below :

#include <fcntl.h>

#include <stdio.h>

#include <unistd.h>

int main( int argc, char *argv[] )

{

int i, fd, ch; // declare local variables

for (i = 1; i < argc; i++)

{

fd = open( argv[i], O_RDONLY );

if ( fd < 0 ) { perror( argv[i] ); continue; }

while ( read( fd, &ch, 1 ) == 1 )

write( STDOUT_FILENO, &ch, 1 );

close( fd );

}

}

after compiling, we run ./mycat /proc/self/maps in Linux and get the results as the following figure, please give the brief explanation s of the result from the views of virtual memory management and the segment -page scheme.

1. (9分) 本题可以有较多解释,基本解释如下

1) the progress virtual address spaces is composed of code segment、data segment、 stack and heap.

2) each segment has different attributes, such as read/write/exccution

3) the libc and ld are mapped into the process address space, and shared by many processes

发表于 2017-05-12 00:17:58 回复(0)