Backtracing a thread in another process

Use the following sample code segment to repeatedly backtrace a thread in another process by using the remote process's pid and thread tid:

char out[1024];
bt_addr_t pc[16];
bt_accessor_t acc;

bt_init_accessor(&acc, BT_PROCESS, remotepid, remotetid);
bt_load_memmap(&acc, &memmap);
bt_sprn_memmap(&acc, out, sizeof(out));

for (i=0; i<10; i++) {
   cnt=bt_get_backtrace(&acc, pc, sizeof(pc)/sizeof(bt_addr_t));
   bt_sprnf_addrs(&memmap, pc, cnt, "%a\n", out, sizeof(out), 0);
   puts(out);
}
bt_unload_memmap(&memmap);
bt_release_accessor(&acc);