Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
trouble with /proc filesystem
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Andrew Benson  
View profile  
 More options Jun 4 1996, 3:00 am
Newsgroups: comp.unix.programmer, comp.unix.solaris, comp.sys.sun.admin
From: d...@mtu.edu (Andrew Benson)
Date: 1996/06/04
Subject: trouble with /proc filesystem

Greets,

        I wanted to get some process information, so I first wrote
a program just to test if I was doing things correctly.  The program
is below.  It takes one argument on the command line  (a process number)
and opens /proc/that-process-number, then does a PIOCPSINFO ioctl to
get some information.  Then I try to print that processes argv[].

        I am running Solaris 2.5 on a sparc 10 (dual cpu).  I'm using
gcc version 2.7.1.

        My test was to start a "sleep 10000" in the background, and then
use its process ID, to test.  My program is named 'testing'. i.e.,

FIRST TEST
                example% gcc -g testing.c -o testing
                example% sleep 10000 &
                [1] 1048
                example% ./testing 1048
                arglist: ./testing 1048
                example%

        I get the arglist of the executing program printed.  Then, I su
to root, and do it again:

SECOND TEST
                example# ./testing 1048
                Segmentation Fault (core dumped)
                example#

THIRD TEST (regular user, under gdb)
                example% gdb ./testing
                [GNU BABBLING MESSAGES REMOVED]
                (gdb) run 1048
                Starting program: /usr/local/home/andrew/c/proc/./testing 1048
                arglist: HZ=100 LD_LIBRARY_PATH=/usr/lib:/usr/openwin/lib

What gives?  I'm pretty certain I'm doing something very wrong, but
what is it?

Thanks,
Andrew Benson (and...@arbitrade.com)
--
REDISTRIBUTION OF THIS WORK BY THE MICROSOFT NETWORK IS STRICTLY PROHIBITED


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Benson  
View profile  
 More options Jun 4 1996, 3:00 am
Newsgroups: comp.unix.programmer, comp.unix.solaris, comp.sys.sun.admin
Followup-To: comp.unix.programmer, comp.unix.solaris, comp.sys.sun.admin
From: d...@mtu.edu (Andrew Benson)
Date: 1996/06/04
Subject: Re: trouble with /proc filesystem

Andrew Benson (d...@mtu.edu) wrote:

: Greets,
:
:       I wanted to get some process information, so I first wrote
: a program just to test if I was doing things correctly.  The program
: is below.  It takes one argument on the command line  (a process number)
: and opens /proc/that-process-number, then does a PIOCPSINFO ioctl to
: get some information.  Then I try to print that processes argv[].
: [...]

I forgot to include the program (Thanks Kevin Thomas for pointing
that out to me).  Here it is:

#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/fault.h>
#include <sys/syscall.h>
#include <sys/procfs.h>
#include <sys/stat.h>
#include <fcntl.h>

int     main(int argc, char **argv)
{
        char            procname[1024];
        prpsinfo_t      p;
        int             fd;
        int             i;

        /* Open process */
        sprintf(procname, "/proc/%d", atol(argv[1]));

        if ((fd = open(procname, O_RDWR)) == -1) {
                perror(procname);
                exit(1);
        }

        /* Get process summary info */
        if (ioctl(fd, PIOCPSINFO, (void *)&p) == -1) {
                perror("PIOCPSINFO");
                exit(2);
        }

        /* Print argv[] of process */
        for(i=0; i < p.pr_argc; ++i)
                printf("%s%s%s", i ? " ": "arglist: ", p.pr_argv[i],
                         ((i+1) == p.pr_argc) ? "\n" : "" );

        close(fd);
        exit(0);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Casper H.S. Dik  
View profile  
 More options Jun 5 1996, 3:00 am
Newsgroups: comp.unix.programmer, comp.unix.solaris, comp.sys.sun.admin
From: cas...@fwi.uva.nl (Casper H.S. Dik)
Date: 1996/06/05
Subject: Re: trouble with /proc filesystem

d...@mtu.edu (Andrew Benson) writes:
>    sprintf(procname, "/proc/%d", atol(argv[1]));

Style (and future portability nit): you're printing a long as an int.
Why not:

        sprintf(procname, "/proc/%s", argv[1]);

>    /* Print argv[] of process */
>    for(i=0; i < p.pr_argc; ++i)
>            printf("%s%s%s", i ? " ": "arglist: ", p.pr_argv[i],
>                     ((i+1) == p.pr_argc) ? "\n" : "" );
>    close(fd);
>    exit(0);

These pointers are relative to the traced processes address space.

You'll need to retrieve them with lseek/read from the fd you just
opened.  The pointers supplied just tell you where the arguments are
in the examined process.

Casper
--
Casper Dik - Sun Microsystems - via my guest account at the University
of Amsterdam.  My work e-mail address is: Casper....@Holland.Sun.COM
Statements on Sun products included here are not gospel and may
be fiction rather than truth.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »