🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.internals
Article #2595

shminfo.c Re: Getting kernel config parameters

#2595
From: Brian Fitzgerald
Date: Thu, 24 Mar 1994 18:24
172 lines
5326 bytes
Archive-name: shminfo
Submitted-by: fitz@rpi.edu (Brian P. Fitzgerald)
Version-number: 1.2
Environment: UNIX

Mike Bandy writes:
>My application won't run unless the kernel has been configured
>with the lines
> 		options SHMSIZE=12288  # Shared Memory
>		options SHMMNI=50      # Shared Memory Segments
>I'd like to verify that the Sun OS 4.1.2 system my program is
>running under has been configured properly.
>
>I can see that they're in struct shminfo in <sys/shm.h>.  How
>do I retrieve them from the running system?  I'd like a non-prived
>solution, but I'll take what I can get.

Try my program.

On my system, it prints:
shmmax 1048576
shmmin 1
shmmni 100
shmseg 0
shmall 0

Brian

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  The tool that generated this
# shell archive is called "shar", and is available by anonymous ftp
# from ftp.uu.net in subdirectory /usenet/comp.sources.unix, and from many
# other places. Check 'archie' for the latest locations.  If this archive
# is complete, you will see the following message at the end:
#		"End of shell archive."
# Contents:  shminfo.c Makefile
# Wrapped by fitzgb@hammer.meche.rpi.edu on Thu Mar 24 13:18:14 1994
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'shminfo.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'shminfo.c'\"
else
echo shar: Extracting \"'shminfo.c'\" \(1900 characters\)
sed "s/^X//" >'shminfo.c' <<'END_OF_FILE'
X/**
X * shminfo - read and print the shared memory information structure
X**/
X/**
X * This program may be copied, redistributed in any form,
X * source or binary, and used for any purpose, provided
X * this copyright notice is retained.
X **/
X#ifndef lint
Xstatic char    *copyright[] = {
X    "@(#)shminfo.c	1.2 3/24/94 (c) Copyright Brian P. Fitzgerald",
X    "Rensselaer Polytechnic Institute",
X    0
X};
X#endif
X
Xvoid            exit();
X
X#include <stdio.h>
X#include <string.h>
X#include <kvm.h>
X#include <nlist.h>
X#include <fcntl.h>
X#include <sys/types.h>
X#include <sys/ipc.h>
X#define KERNEL 1
X#include <sys/shm.h>
X
Xstruct nlist    nlst[] =
X{
X#define X_SHMINFO                  0
X    {"_shminfo"},
X    {0}
X};
X
X
X#define Printf (void) printf
X#define Fprintf (void) fprintf
X#define Sprintf (void) sprintf
Xint             errno;
X#define error(m) \
X((Fprintf(stderr, "%s: ", progname)), (void) \
X (errno ? (perror (m), 0) : ((void)fputs (m, stderr),(void)fputc ('\n', stderr), 0)))
X
X#define Fail(m) (error(m), exit(1))
X
Xchar           *progname;
X
X/* ARGSUSED */
Xint
Xmain(argc, argv)
X    int             argc;
X    char          **argv;
X{
X    char           *namefile;
X    kvm_t          *kd;
X    struct shminfo  shminfo;
X
X    namefile = "/vmunix";
X    progname = strrchr(argv[0], '/');
X    progname = progname ? ++progname : argv[0];
X
X    if ((kd = kvm_open(namefile, (char *) NULL,
X		       (char *) NULL, O_RDONLY, progname)) == 0) {
X	exit(1);
X    }
X    if (kvm_nlist(kd, nlst)) {
X	Fail("can't get namelist");
X    }
X    if (kvm_read(kd, nlst[X_SHMINFO].n_value, (char *) &shminfo, sizeof shminfo)
X	!= sizeof shminfo) {
X	Fail("can't read shminfo");
X    }
X    Printf("shmmax %d\n", shminfo.shmmax);
X    Printf("shmmin %d\n", shminfo.shmmin);
X    Printf("shmmni %d\n", shminfo.shmmni);
X    Printf("shmseg %d\n", shminfo.shmseg);
X    Printf("shmall %d\n", shminfo.shmall);
X    (void) exit(0);
X    /* NOTREACHED */
X}
END_OF_FILE
if test 1900 -ne `wc -c <'shminfo.c'`; then
    echo shar: \"'shminfo.c'\" unpacked with wrong size!
fi
# end of 'shminfo.c'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(354 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
XCFLAGS		= -g
X
XPROG		= shminfo
X
XOBJS		= shminfo.o
XLNS		= shminfo.ln
XLIBS		= -lkvm
X
Xall: $(PROG)
X
X
X$(PROG): 	$(OBJS)
X	$(LINK.c) -o $(PROG) $(OBJS) $(LIBS)
X
Xinstall: shminfo
X	chown root.kmem shminfo
X	chmod 2755 shminfo
X
Xlint: 	$(LNS)
X	$(LINT.c) $(LNS) $(LIBS)
X
Xshar:
X	shar shminfo.c Makefile > shminfo.shar
X
Xclean:
X	$(RM) core *.out *.BAK *.o $(PROG) *.ln 
END_OF_FILE
if test 354 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
echo shar: End of shell archive.
exit 0
Technical Details
Message-ID: <2mslsp$ca2@usenet.rpi.edu>
Path: arc1-ca.pugleaf.net!wupost!math.ohio-state.edu!howland.reston.ans.net!news.intercon.com!panix!zip.eecs.umich.edu!newsxfer.itd.umich.edu!gumby!yale!yale.edu!noc.near.net!usenet.elf.com!rpi!fitzgb
References: <2ms3cm$nrp@aplcomm.jhuapl.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!wupost!math.ohio-state.edu!howland.reston.ans.net!news.intercon.com!panix!zip.eecs.umich.edu!newsxfer.itd.umich.edu!gumby!yale!yale.edu!noc.near.net!usenet.elf.com!rpi!fitzgb
From: fitzgb@fracture.meche.rpi.edu (Brian Fitzgerald)
Newsgroups: comp.unix.internals,alt.sources
Subject: shminfo.c Re: Getting kernel config parameters
Followup-To: comp.unix.internals
Date: 24 Mar 1994 18:24:25 GMT
Organization: Rensselaer Polytechnic Institute, Troy NY, USA
Lines: 172
Message-ID: <2mslsp$ca2@usenet.rpi.edu>
References: <2ms3cm$nrp@aplcomm.jhuapl.edu>
NNTP-Posting-Host: fracture.meche.rpi.edu