Belle II Software  release-08-01-10
removerb.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <string>
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 
15 #include <sys/ipc.h>
16 #include <sys/shm.h>
17 #include <sys/sem.h>
18 
19 #include "framework/pcore/RingBuffer.h"
20 
21 using namespace std;
22 
23 int main(int argc, char** argv)
24 {
25  if (argc < 2) {
26  printf("remove : rbufname \n");
27  exit(-1);
28  }
29  string pathname = string("/tmp/") + string(getenv("USER"))
30  + string("_RB_") + string(argv[1]);
31  FILE* fd = fopen(pathname.c_str(), "r");
32  if (fd == NULL) {
33  printf("[removerb] No such RingBuffer : %s\n", argv[1]);
34  exit(-1);
35  }
36  int shmid, semid;
37  fscanf(fd, "%d", &shmid);
38  fscanf(fd, "%d", &semid);
39  fclose(fd);
40 
41  printf("Removing shmid = %d, semid = %d\n", shmid, semid);
42  shmctl(shmid, IPC_RMID, (struct shmid_ds*) 0);
43  semctl(semid, 1, IPC_RMID);
44  printf("Removing pathfile = %s\n", pathname.c_str());
45  unlink(pathname.c_str());
46 
47  // remove id file
48  char fname[1024];
49  sprintf(fname, "/tmp/SHM%d-SEM%d-RB_%s", shmid, semid, argv[1]);
50  unlink(fname);
51 
52  return 0;
53 }
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:91