/* nick testing ps */
#define _GNU_SOURCE
#include <ps.h>

int printproc(struct proc_stat *ps)
{
  printf("%d",proc_stat_pid(ps));
  if (proc_stat_args_len(ps))
    {
      printf(" %s",proc_stat_args(ps)[0]);
    }
  printf(" %d \n",proc_stat_args_len(ps));
  return 0;
}

main ()
{
  struct proc_stat_list *mysl;
  struct ps_context *mycontext;
  process_t myproc;

  /* initialize */
  myproc = getproc();
  ps_context_create(myproc,&mycontext);
  proc_stat_list_create(mycontext, &mysl);


  proc_stat_list_add_all(mysl,0,0);

  /* do it */
  printf("Number of processes: %d\n",mysl->num_procs);
  proc_stat_list_for_each(mysl, &printproc);

  /* deinitialize */
  proc_stat_list_free(mysl);
  ps_context_free(mycontext);
  mach_port_deallocate(mach_task_self(), myproc);
}

