Esempio n. 1
0
int main(int argc, char **argv) {

    pid_t pid = 0;
    int status = 0;

    
    signal(SIGINT,signal_handler);
    signal(SIGQUIT,signal_handler);
    signal(SIGSTOP,signal_handler);
    
    shmid = Shmget(SHM_KEY,SVSHM_FLAG);


    if(-1 == (pid = fork())) {
        perror("fork");
        return(-1);
    }

    /* child process */
    if(0 == pid) { 
        
        //start fileclient
        fileclient(shmid);
        exit(0);
    }

    /* parent process */
    //start fileserver
    fileserver(shmid);

    waitpid(pid,&status,0);

    rmshm(shmid);
    return 0;
}
Esempio n. 2
0
int
main(int argc, char **argv)
{
	int		c, id, oflag;
	char	*ptr;
	size_t	length;

	oflag = SVSHM_MODE | IPC_CREAT;
	while ( (c = Getopt(argc, argv, "e")) != -1) {
		switch (c) {
		case 'e':
			oflag |= IPC_EXCL;
			break;
		}
	}
	if (optind != argc - 2)
		err_quit("usage: shmget [ -e ] <pathname> <length>");
	length = atoi(argv[optind + 1]);

	id = Shmget(Ftok(argv[optind], 0), length, oflag);
	ptr = Shmat(id, NULL, 0);

	printf("shm addr : %p\n", ptr);

	exit(0);
}
Esempio n. 3
0
   int SMP_create(size_t size) {

      int semflg = 0600;

      DDI_Comm *comm     = (DDI_Comm *) Comm_find(DDI_COMM_WORLD); /* hardcoded atm */
      SMP_Data *new_data = (SMP_Data *) Malloc(sizeof(SMP_Data));
      SMP_Data *end_data = (SMP_Data *) SMP_find_end();

      STD_DEBUG((stdout,"%s: Entered DDI_SMP_Create.\n",DDI_Id()))

      if(end_data) end_data->next = (void *) new_data;
      else gv(smp_base_data) = (SMP_Data *) new_data;

    # if defined USE_SYSV
      Comm_sync_smp(comm);
      if(comm->me_local == 0) { 
         new_data->handle = gv(smp_data_id)++; 
         new_data->shmid  = gv(shmid) = Shmget(IPC_PRIVATE,size,SHM_R|SHM_W);
         new_data->semid  = Semget(IPC_PRIVATE,1,semflg);
         new_data->size   = size;
         new_data->next   = NULL;
      }
      Comm_bcast_smp(new_data,sizeof(SMP_Data),0,comm);
      new_data->addr = Shmat(new_data->shmid,0,0);
      MAX_DEBUG((stdout,"%s: SMP memory [%i] shmid=%i, semid=%i, addr=%x.\n",
                 DDI_Id(),new_data->handle,new_data->shmid,new_data->semid,new_data->addr))
      Comm_sync_smp(comm);
      if(comm->me_local == 0) { Shmctl(new_data->shmid,IPC_RMID,NULL); gv(shmid) = 0; }
      Comm_sync_smp(comm);
    # else
      new_data->handle = gv(smp_data_id)++;
      new_data->size   = size;
      new_data->next   = NULL;
      new_data->addr   = Malloc(size);
/*
         MWS: May 2010
     It appears above that systems without SysV memory are expected to
     allocate Process-replicated memory instead of Node-replicated, and
     get on with it.  If these are duplicated, at full size, as it appears,
     that's likely devastating for the system total memory usage.

     The parallel CCSD(T) on IBM Blue Gene/P got into a deadlock, but
     other systems with sockets or MPI seem to work if allowed to proceed.
     At this time, we kill off just the BG here...

*/
       # ifdef IBMBG
         fprintf(stdout,"DDI compiled w/o SysV operating system support.\n");
         fprintf(stdout,"IBM/BG parallel CCSD(T) cannot run w/o SysV.\n");
         Fatal_error(911);
       # endif
    # endif
      
      return new_data->handle;
   }
Esempio n. 4
0
int
main(int argc, char **argv)
{
	int		i, j, shmid[MAX_NIDS];
	void	*addr[MAX_NIDS];
	unsigned long	size;

		/* 4see how many identifiers we can "open" */
	for (i = 0; i <= MAX_NIDS; i++) {
		shmid[i] = shmget(IPC_PRIVATE, 1024, SVSHM_MODE | IPC_CREAT);
		if (shmid[i] == -1) {
			printf("%d identifiers open at once\n", i);
			break;
		}
	}
	for (j = 0; j < i; j++)
		Shmctl(shmid[j], IPC_RMID, NULL);

		/* 4now see how many we can "attach" */
	for (i = 0; i <= MAX_NIDS; i++) {
		shmid[i] = Shmget(IPC_PRIVATE, 1024, SVSHM_MODE | IPC_CREAT);
		addr[i] = shmat(shmid[i], NULL, 0);
		if (addr[i] == (void *) -1) {
			printf("%d shared memory segments attached at once\n", i);
			Shmctl(shmid[i], IPC_RMID, NULL);	/* the one that failed */
			break;
		}
	}
	for (j = 0; j < i; j++) {
		Shmdt(addr[j]);
		Shmctl(shmid[j], IPC_RMID, NULL);
	}

		/* 4see how small a shared memory segment we can create */
	for (size = 1; ; size++) {
		shmid[0] = shmget(IPC_PRIVATE, size, SVSHM_MODE | IPC_CREAT);
		if (shmid[0] != -1) {		/* stop on first success */
			printf("minimum size of shared memory segment = %lu\n", size);
			Shmctl(shmid[0], IPC_RMID, NULL);
			break;
		}
	}

		/* 4see how large a shared memory segment we can create */
	for (size = 65536; ; size += 4096) {
		shmid[0] = shmget(IPC_PRIVATE, size, SVSHM_MODE | IPC_CREAT);
		if (shmid[0] == -1) {		/* stop on first failure */
			printf("maximum size of shared memory segment = %lu\n", size-4096);
			break;
		}
		Shmctl(shmid[0], IPC_RMID, NULL);
	}

	exit(0);
}
Esempio n. 5
0
int 
main(int argc,char **argv)
{
	int id;

	if(argc!=2)
		err_quit("ysage: shmrmid <pathname>");

	id=Shmget(Ftok(argv[1],0),0,SVSHM_MODE);
	Shmctl(id,IPC_RMID,NULL);
	exit(0);
}
Esempio n. 6
0
int main(int argc, char **argv)
{
	int i, id;
	struct shmid_ds buff;
	unsigned char *ptr;

	if (argc != 2)
		err_quit("Usage: write <pathname>");

	id = Shmget(Ftok(argv[1], 0), 0, SVSHM_MODE);
	ptr = Shmat(id, NULL, 0);
	Shmctl(id, IPC_STAT, &buff);

	for (i = 0; i < buff.shm_segsz; i++)
		*ptr++ = i % 256;
	exit(0);
}