Program:
#include<stdio.h>
#include<sys/types.h>
#include<malloc.h>
main()
{
    int *i1, *i2;
    printf("sbrk(0) before malloc(): %x\n", sbrk(0));
    i1 = (int *) malloc(sizeof(int));
    printf("sbrk(0) after `i1 = (int *) malloc(4)': %x\n", sbrk(0));
    i2 = (int *) malloc(sizeof(int));
    printf("sbrk(0) after `i2 = (int *) malloc(4)': %x\n", sbrk(0));
}
Output 1:
 mohanraj@ltsp63:~/Development/chap8$ strace -e sbrk ./a.out
 strace: invalid system call `sbrk'
 mohanraj@ltsp63:~/Development/chap8$ 
Output 2:
 mohanraj@ltsp63:~/Development/chap8$ strace -e brk ./a.out
 brk(0)                                  = 0x8380000
 brk(0)                                  = 0x8380000
 sbrk(0) before malloc(4): 8380000
 brk(0x83a1000)                          = 0x83a1000
 sbrk(0) after `i1 = (int *) malloc(4)': 83a1000
 sbrk(0) after `i2 = (int *) malloc(4)': 83a1000
 mohanraj@ltsp63:~/Development/chap8$
Doubts:
Malloc function allocate memory in heap using the sbrk system call. Here also the program break is changed after the calling of malloc.
But, the output shows only the brk system call. strace command throws an error as "sbrk is invalid system call". Then, how is memory
allocated using malloc?
But, after the malloc statement is called, the output shows the following line "brk(0x83a1000)". Here, why the brk value is changed and why the sbrk is not printed on the output ?
 
     
    