Graphics Programs Reference
In-Depth Information
mmap2(0xb7ee4000, 9596, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) =
0xb7ee4000
close(3) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7db2000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb7db26b0, limit:1048575, seg_32bit:1,
contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
mprotect(0xb7ee0000, 8192, PROT_READ) = 0
munmap(0xb7ee7000, 61323) = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7ef5000
write(1, "Hello, world!\n", 13Hello, world!
) = 13
exit_group(0) = ?
Process 11528 detached
reader@hacking:~/booksrc $
As you can see, the compiled program does more than just print a string.
The system calls at the start are setting up the environment and memory
for the program, but the important part is the write() syscall shown in bold.
This is what actually outputs the string.
The Unix manual pages (accessed with the man command) are sep-
arated into sections. Section 2 contains the manual pages for system calls,
so man 2 write will describe the use of the write() system call:
Man Page for the write() System Call
WRITE(2) Linux Programmer's Manual
WRITE(2)
NAME
write - write to a file descriptor
SYNOPSIS
#include <unistd.h>
ssize_t write(int fd, const void *buf, size_t count);
DESCRIPTION
write() writes up to count bytes to the file referenced by the file
descriptor fd from the buffer starting at buf. POSIX requires that a
read() which can be proved to occur after a write() returns the new
data. Note that not all file systems are POSIX conforming.
The strace output also shows the arguments for the syscall. The buf
and count arguments are a pointer to our string and its length. The fd
argument of 1 is a special standard file descriptor. File descriptors are used
for almost everything in Unix: input, output, file access, network sockets,
and so on. A file descriptor is similar to a number given out at a coat check.
Opening a file descriptor is like checking in your coat, since you are given
a number that can later be used to reference your coat. The first three file
descriptor numbers (0, 1, and 2) are automatically used for standard input,
output, and error. These values are standard and have been defined in several
places, such as the /usr/include/unistd.h file on the following page.
Search WWH ::




Custom Search