How to configure the 'semaphore' and 'shared memory'?

How to configure the 'semaphore' and 'shared memory'?

Post by Hsi-ming L » Tue, 13 Feb 1996 04:00:00



Dear All:

Recently I am installing a software on two SUN Sparcstations which run
Solaris 2.4.  The software requires the semaphore facility to be
available on the system.  Unfortunately, I realized it is on one of
the system only.

Searching through the manual, I cannot find anywhere describes how to
change it.  Has anyone experienced the same?

Cheers,
Hsi-ming Lee
===

1. Outout of the 'ipcs' command on a system which has semaphore off
===================================================================

    IPC status from <running system> as of Mon Feb 12 08:19:39 1996
    Message Queue facility not in system.
    Shared Memory facility not in system.
    Semaphore facility not in system.

2. Outout of the 'ipcs' command on a system which has semaphore on
==================================================================

    IPC status from <running system> as of Mon Feb 12 08:15:18 1996
    Message Queue facility not in system.
    Shared Memory:
    m      0 0x41018d67 --rw-rw-rw-     root     root
    m      1 0x41018d68 --rw-rw-rw-     root     root
    m      2 0x41000009 --rw-rw-rw-     root     root
    m      3 0x4d018d4d --rw-rw-rw-     root     root
    Semaphores:
    s      0 0x41018d68 --ra-ra-ra-     root     root
    s      1 0x41000009 --ra-ra-ra-     root     root
    s      2 0x013d8483 --ra-r--r--     root     root
    s      3 0x0x00000000 --ra-ra-ra-     root     root
--

 
 
 

How to configure the 'semaphore' and 'shared memory'?

Post by Stephen C. Fitc » Thu, 22 Feb 1996 04:00:00


Check out the /etc/system files on both machines. See the following
line of tags that configure various parameters within the sysV msgQ,
Sema, and shared memory environment:

set semsys:seminfo_semmap=10
set semsys:seminfo_semmni=100
set semsys:seminfo_semmns=1000
set semsys:seminfo_semmnu=30
set semsys:seminfo_semmsl=50
set semsys:seminfo_semopm=10
set semsys:seminfo_semume=10
set semsys:seminfo_semusz=96
set semsys:seminfo_semvmx=32767
set semsys:seminfo_semaem=16384

set shmsys:shminfo_shmmax=10000000
set shmsys:shminfo_shmmin=1
set shmsys:shminfo_shmmni=100
set shmsys:shminfo_shmseg=10
*

The structures set here can be found (and are illustrated) in the
/usr/include/sys/{sem,msg,shd}.h files respectively.

Steve

Quote:

> 1. Outout of the 'ipcs' command on a system which has semaphore off
> ===================================================================

>     IPC status from <running system> as of Mon Feb 12 08:19:39 1996
>     Message Queue facility not in system.
>     Shared Memory facility not in system.
>     Semaphore facility not in system.

> 2. Outout of the 'ipcs' command on a system which has semaphore on
> ==================================================================

>     IPC status from <running system> as of Mon Feb 12 08:15:18 1996
>     Message Queue facility not in system.
>     Shared Memory:
>     m      0 0x41018d67 --rw-rw-rw-     root     root
>     m      1 0x41018d68 --rw-rw-rw-     root     root
>     m      2 0x41000009 --rw-rw-rw-     root     root
>     m      3 0x4d018d4d --rw-rw-rw-     root     root
>     Semaphores:
>     s      0 0x41018d68 --ra-ra-ra-     root     root
>     s      1 0x41000009 --ra-ra-ra-     root     root
>     s      2 0x013d8483 --ra-r--r--     root     root
>     s      3 0x0x00000000 --ra-ra-ra-     root     root
> --


 
 
 

How to configure the 'semaphore' and 'shared memory'?

Post by Kevin Nicke » Fri, 23 Feb 1996 04:00:00



: Check out the /etc/system files on both machines. See the following

: The structures set here can be found (and are illustrated) in the
: /usr/include/sys/{sem,msg,shd}.h files respectively.
I don't know as I'd call the .h files an illustration... the man pages,
*maybe*.

: > 1. Outout of the 'ipcs' command on a system which has semaphore off
: > 2. Outout of the 'ipcs' command on a system which has semaphore on
Actually, what was shown only states wether the systems are active.  The ones
you tagged as "on" are really semaphores which have not been cleaned up.
Before and after your programs have finished and deleted the semaphores from
the system using sem_ctl, it should look like (2).  During the execution,
it should look like (2).

Here are a couple toy programs I wrote (for solaris 2.4) to figgur this very
thing out.  I won't claim that they are minimal or even good.  Note
particularly that since the shared mem program doesn't use semaphores, you
don't know what order they'll access the shared memory in.  Also note that
the shared mem program doesn't remove the segment, you'll have to do it
afterwards using killshm.c (a bit awkward, but it let me separate the two
concepts)

Standard disclaimers apply, and all that.  YMMV.

--kevin

------ semaphore.c --------

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/sem.h>

extern int errno;

int main (int argc, char *argv[]) {
 pid_t parent, child;
 int semid;
 struct sembuf sops;

 errno = 0;
 parent = getpid();

 /* Create Semaphore */
 if((semid=semget(ftok("/tmp",42),1,IPC_CREAT|SEM_R|SEM_A))==-1) {
   perror("semget");
   exit(0);
   }

 sops.sem_num = 0;  /* semaphore number */
 sops.sem_op = 1 ;  /* semaphore operation - set semaphore*/
 sops.sem_flg = 0 ; /* operation flags */
 semop(semid,&sops,1); /* set semaphore */

 printf("Before fork\n");
 child = fork();

 if (child != 0) {
   printf("Parent Process, pid %d\n",getpid());
   printf("Parent: Waiting for semaphore\n");
   sops.sem_op = 0 ;  /* semaphore operation - wait for semaphore to be zero */
   semop(semid,&sops,1);
   printf("Parent: Semaphore Clear!\n");

 } else {
   printf("\nChild Process, pid %d\n",getpid());
   printf("Child: About to clear semaphore\n");
   sops.sem_op = -1 ;  /* semaphore operation - clear semaphore */
   semop(semid,&sops,1);
   printf("Child: Semaphore Clear!\n");
   semctl(semid,1,IPC_RMID,NULL);
 }

Quote:}

------ sharedmem.cc ---------------
#include <iostream.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>

extern int errno;

int main (int argc, char *argv[]) {
 pid_t parent, child;
 char *string = NULL;
 int shmid;
 void *make_shm(int &shmid, size_t size);

 errno = 0;
 parent = getpid();

 string = (char *) make_shm(shmid, 50*sizeof(char));
 if ((int)string==-1) { perror("make_shm"); exit(0); }

 sprintf(string,"Original String");
 cout << "String before fork : " << string << "\n";
 child = fork();

 if (child != 0) {
   cout << "Parent Process, pid " << getpid() << "\n";

   printf("Parent: string '%s', location = %p\n",string,string);
   sprintf(string,"Parent String");
   printf("Parent: string '%s', location = %p\n",string,string);

   if(shmdt(string)==-1) {perror("Parent:shmdt");exit(0);}
 } else {
   cout << "\nChild Process, pid " << getpid() << "\n";

   printf("Child: string '%s', location = %p\n",string,string);
   sprintf(string,"Child String");
   printf("Child: string '%s', location = %p\n",string,string);

   if(shmdt(string)==-1) {perror("Child:shmdt");exit(0);}
 }

Quote:}

// ---------------------------------------------------------------------
// make_shm - create shared memory segment.
// args : shmid - id of created segment - MODIFIED
//        size - size of segment to create
// ---------------------------------------------------------------------
void *make_shm(int &shmid, size_t size) {
 void *address = NULL;
 struct shmid_ds shm_ds;

 errno = 0;

 if((shmid=shmget(ftok("/tmp",42),size,IPC_CREAT|SHM_R|SHM_W))==-1) {
   perror("shmget");
   return (void *)-1;
   }

 address = shmat(shmid,NULL,SHM_SHARE_MMU|SHM_R|SHM_W);
 if ((int)address==-1) {
     perror("shmat");
     return (void *)-1;
     }

 return address;

Quote:}

----- killshm.c ------

#include <sys/types.h>
#include <errno.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
  int i;
  for (i=1;i<argc;i++) {
   printf("Killing shm %d\n",atoi(argv[i]));
   shmctl(atoi(argv[i]),IPC_RMID,(struct shmid_ds *)NULL);
        }
  return 0;

Quote:}

--

 
 
 

How to configure the 'semaphore' and 'shared memory'?

Post by Andries Holtzhause » Sat, 24 Feb 1996 04:00:00


It should not happen, but sometimes the dynamic loading of the shared
memory driver does not happen. You can force it by putting this line in
/etc/system:

forceload: sys/shmsys

There are similar commands for message queues and semaphores.


> Check out the /etc/system files on both machines. See the following
> line of tags that configure various parameters within the sysV msgQ,
> Sema, and shared memory environment:

> set semsys:seminfo_semmap=10
> set semsys:seminfo_semmni=100
> set semsys:seminfo_semmns=1000
> set semsys:seminfo_semmnu=30
> set semsys:seminfo_semmsl=50
> set semsys:seminfo_semopm=10
> set semsys:seminfo_semume=10
> set semsys:seminfo_semusz=96
> set semsys:seminfo_semvmx=32767
> set semsys:seminfo_semaem=16384

> set shmsys:shminfo_shmmax=10000000
> set shmsys:shminfo_shmmin=1
> set shmsys:shminfo_shmmni=100
> set shmsys:shminfo_shmseg=10
> *

> The structures set here can be found (and are illustrated) in the
> /usr/include/sys/{sem,msg,shd}.h files respectively.

> Steve

> > 1. Outout of the 'ipcs' command on a system which has semaphore off
> > ===================================================================

> >     IPC status from <running system> as of Mon Feb 12 08:19:39 1996
> >     Message Queue facility not in system.
> >     Shared Memory facility not in system.
> >     Semaphore facility not in system.

> > 2. Outout of the 'ipcs' command on a system which has semaphore on
> > ==================================================================

> >     IPC status from <running system> as of Mon Feb 12 08:15:18 1996
> >     Message Queue facility not in system.
> >     Shared Memory:
> >     m      0 0x41018d67 --rw-rw-rw-     root     root
> >     m      1 0x41018d68 --rw-rw-rw-     root     root
> >     m      2 0x41000009 --rw-rw-rw-     root     root
> >     m      3 0x4d018d4d --rw-rw-rw-     root     root
> >     Semaphores:
> >     s      0 0x41018d68 --ra-ra-ra-     root     root
> >     s      1 0x41000009 --ra-ra-ra-     root     root
> >     s      2 0x013d8483 --ra-r--r--     root     root
> >     s      3 0x0x00000000 --ra-ra-ra-     root     root
> > --

--
Experience is directly proportional to the amount of equipment ruined.