Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!prcrs!paul From: paul@prcrs.UUCP (Paul Hite) Newsgroups: comp.sys.hp Subject: Re: System-configurable parameters Message-ID: <1284@prcrs.UUCP> Date: 8 Nov 90 20:03:42 GMT References: <675@modus.sublink.ORG> Organization: PRC Realty Systems, McLean, VA Lines: 68 In article <675@modus.sublink.ORG>, luke@modus.sublink.ORG (Luciano Mannucci) writes: > Does anyone know how a program (i.e. a C program) can test a system > configurable parameter (such as shmseg or msgmax) in order to complain > propperly whithout a need of generating a system error? > > luke. Well there's a problem with this approach. You're trying to do something like: if(verify_that_a_resource_is_available()) use_resource(); else complain_nicely(); But between the "verify" and the "use", some other process could consume the resource. The standard approach is to simply check the return code from shmget. errno will tell you what the problem is and your program can then issue whatever error message you like. Am I missing something? What's wrong with this approach? Anyway, I've seen another request about obtaining system configurable parameters. There is no truly portable way to do this. Basicly, you just poke around /dev/kmem looking for them. Sometimes you can find what you're looking for. In the case of shmseg, I first tried "nm /hp-ux | grep shmseg". No luck. So then I tried "nm /hp-ux | grep shm" and I found a bunch of stuff. I ignored the code and looked at the data. I knew what my shm parameters were so I could recognize them when I found them. They were stored in a neat little table called shminfo. A program to do this would be: #include #include #include main() { int fdkern; static struct nlist nl[2] = { { "shminfo" } , { NULL } }; int shmmax; int shmmin; int shmmni; int shmseg; char *address; nlist("/hp-ux", nl); address = nl[0].n_value; printf("address = %d\n", (int) address); fdkern = open("/dev/kmem", O_RDONLY); printf("fdkern = %d\n", fdkern); lseek(fdkern,(long) address,0); read(fdkern, (char *) &shmmax, sizeof(shmmax)); printf("max shared memory segment size = %x\n", (int)shmmax); read(fdkern, (char *) &shmmin, sizeof(shmmin)); printf("min shared memory segment size = %x\n", (int)shmmin); read(fdkern, (char *) &shmmni, sizeof(shmmni)); printf("max shared memory ids = %d\n", (int)shmmni); read(fdkern, (char *) &shmseg, sizeof(shmseg)); printf("max shared memory segments = %d\n", (int)shmseg); exit(0); } But the rub is that this program must be able to read /dev/kmem. Like ps, it should be sgid'd to sys. Paul Hite PRC Realty Systems McLean,Va uunet!prcrs!paul (703) 556-2243 You can't tell which way the train went by studying its tracks.