📄 cleanupsem.cpp
字号:
/*-< CLEANUPSEM.CPP >------------------------------------------------*--------*/
// FastDB Version 1.0 (c) 1999 GARRET * ? *
// (Main Memory Database Management System) * /\| *
// * / \ *
// Created: 05-Aug-2004 K.A. Knizhnik * / [] \ *
// Last update: 05-Aug-2004 K.A. Knizhnik * GARRET *
//-------------------------------------------------------------------*--------*
// Unix utility to cleanup FastDB semaphores
//-------------------------------------------------------------------*--------*
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char* keyFileDir = "/tmp/";
int getKey(char* databaseName, char* suffix) {
char fileName[1024];
strcat(strcpy(fileName, databaseName), suffix);
return ftok(fileName, '0');
}
void removeSemaphore(char* databaseName, char* suffix) {
int key = getKey(databaseName, suffix);
if (key >= 0) {
int id = semget(key, 0, 0);
if (id >= 0) {
semctl(id, 0, IPC_RMID, NULL);
}
}
}
void removeSharedMemory(char* databaseName, char* suffix) {
int key = getKey(databaseName, suffix);
if (key >= 0) {
int id = shmget(key, 0, 0);
if (id >= 0) {
shmctl(id, IPC_RMID, NULL);
}
}
}
int main(int argc, char* argv[]) {
if (argc < 2) {
printf("Usage: cleanupsem DATABASE-NAME\n");
return 1;
}
char* databaseName = argv[1];
if (strchr(databaseName, '/') == NULL) {
char* fullName = new char[strlen(keyFileDir) + strlen(databaseName) + 1];
databaseName = strcat(strcpy(fullName, keyFileDir), databaseName);
}
removeSharedMemory(databaseName, ".dm");
removeSemaphore(databaseName, ".in");
removeSemaphore(databaseName, ".ws");
removeSemaphore(databaseName, ".rs");
removeSemaphore(databaseName, ".us");
removeSemaphore(databaseName, ".bce");
removeSemaphore(databaseName, ".dce");
removeSemaphore(databaseName, ".bce");
removeSemaphore(databaseName, ".cs");
removeSemaphore(databaseName, ".mcs");
printf("All semaphores are removed\n");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -