Re: [AD] No more END_OF_MAIN on *nix!

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> I tried digging up some information on using the C procfs API I'll let 
you 
> know what I dig up.

Ok, I'd like to know the output of the following program from as many 
different flavours of UNIX as possible. I've tested it on Solaris and 
OSF1. They seem to mildly disagree on the string that appears after 
invocation = in the output: Solaris prints the entire argument list 
starting from argv[0] (but the cool thing is that it will let you know 
what argc and argv for the program are), whereas OSF1 only seems to 
display argv[0] here.
Other than that, I got the impression, from reading through some 
documentation, that this is standard across different flavours of UNIX. I 
initially tried it on Solaris, and it worked on OSF when I removed argc 
amd argv.

Oh, this won't compile or run on Linux (it doesn't have a compatible <sys/
procfs.h>).

Evert

#include  <stdio.h>
#include  <fcntl.h>
#include  <unistd.h>
#include  <sys/procfs.h>

int main(int argc, char *argv[])
{
   int ifd;
   int c;
   char filename[16];
   struct prpsinfo psinfo;

   sprintf(filename, "/proc/%d", getpid() );
   ifd = open(filename, O_RDONLY);
   ioctl(ifd, PIOCPSINFO, &psinfo);
   close(ifd);

   printf("argv[0] = %s\n", argv[0]);
   printf("processname = %s\n", psinfo.pr_fname);
   printf("invocation = %s\n", psinfo.pr_psargs);
   
   /* The following also work on Solaris, but not OSF 1 */
#if 0
   printf("argc = %d\n", psinfo.pr_argc);
   printf("argv = %p\n", psinfo.pr_argv);

   for (c=0; c<psinfo.pr_argc; c++)
      fprintf(stderr, "argv[%d] = %s\n", c, psinfo.pr_argv[c]);
#endif

   return 0;
}





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/