home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GCC258_4.LHA / gcc / bin / dump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-05  |  2.3 KB  |  90 lines

  1. #include <exec/types.h>
  2. #include <exec/tasks.h>
  3. #include <exec/interrupts.h>
  4. #include <libraries/dos.h>
  5. #include <sys/types.h>
  6. #include <sys/param.h>
  7. #include <sys/time.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11.  
  12. #include <user.h>
  13.  
  14. void dump_proc (char *);
  15. extern struct ixemul_base *ixemulbase;
  16.  
  17. struct death_msg {
  18.   struct MinNode    dm_node;
  19.   struct Process    *dm_child;
  20.   int            dm_pgrp;
  21.   int            dm_status;
  22.   struct rusage        dm_rusage;
  23. };
  24.  
  25. #define PIPE_SIZE    5120
  26.  
  27. struct tmp_pipe {
  28.   u_short    tp_flags;        /* see below */
  29.   u_char    tp_buffer[PIPE_SIZE];
  30.   u_char    *tp_reader, *tp_writer;    /* buffer pointers.
  31.                        when tp_reader==tp_writer, no data
  32.                        is available */
  33. };
  34.  
  35. int
  36. main (int argc, char *argv[])
  37. {
  38.   while (*++argv)
  39.     dump_proc (*argv);
  40.  
  41.   return 0;
  42. }
  43.  
  44. void
  45. dump_proc (char *pid_str)
  46. {
  47.   pid_t pid = atoi (pid_str);
  48.   struct Task *t;
  49.   
  50.   if ((t=(struct Task *)pid) && !(pid & 1) && 
  51.       (t->tc_Node.ln_Type == NT_TASK || 
  52.        t->tc_Node.ln_Type == NT_PROCESS))
  53.     {
  54.       struct user *p = (struct user *) t->tc_TrapData;
  55.       struct death_msg *dm, *ndm;
  56.  
  57.       if (!p || ixemulbase != p->u_ixbase)
  58.         fprintf (stderr, "process $%lx does not use ixemul.library.\n", t);
  59.       else
  60.     {
  61.       printf ("Process $%lx:\n", t);
  62.       printf ("  p_flag    = %d\n", p->p_flag);
  63.       printf ("  p_stat    = %d\n", p->p_stat);
  64.       printf ("  p_sig     = $%lx\n", p->p_sig);
  65.       printf ("  p_sigmask = $%lx\n", p->p_sigmask);
  66.       printf ("  p_sigign  = $%lx\n", p->p_sigignore);
  67.       printf ("  p_sigcat  = $%lx\n", p->p_sigcatch);
  68.       printf ("  p_wchan   = $%lx\n", p->p_wchan);
  69.       printf ("  p_wmesg   = %s\n", p->p_wmesg);
  70.       if (p->p_wmesg && (!strcmp (p->p_wmesg, "pread") || !strcmp (p->p_wmesg, "pwrite")))
  71.         {
  72.           struct tmp_pipe *tp = (struct tmp_pipe *) p->p_wchan;
  73.           printf ("    tmp_pipe:\n");
  74.           printf ("    tp_flags = $%lx, tp_reader = @%ld, tp_writer = @%ld\n",
  75.               tp->tp_flags, 
  76.               tp->tp_reader - tp->tp_buffer,
  77.               tp->tp_writer - tp->tp_buffer);
  78.         }
  79.       printf ("  p_zombies:\n");
  80.       for (dm  = (struct death_msg *) p->p_zombies.mlh_Head;
  81.            ndm = (struct death_msg *) dm->dm_node.mln_Succ;
  82.            dm  = ndm)
  83.         printf ("    pid=$%lx, pgrp=$%lx, status=$%lx\n",
  84.                 dm->dm_child, dm->dm_pgrp, dm->dm_status);
  85.       printf ("  p_cptr    = $%lx\n", p->p_cptr);
  86.       printf ("\n");
  87.     }
  88.     }
  89. }
  90.