本文整理汇总了C++中rm_shm函数的典型用法代码示例。如果您正苦于以下问题:C++ rm_shm函数的具体用法?C++ rm_shm怎么用?C++ rm_shm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rm_shm函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cleanup
/*
* cleanup() - performs all the ONE TIME cleanup for this test at completion
* or premature exit.
*/
void
cleanup(void)
{
/* if they exist, remove the shared memory resources */
rm_shm(shm_id_1);
rm_shm(shm_id_2);
if (seteuid(0) == -1) {
tst_resm(TINFO, "setuid failed to "
"to set the effective uid to %d",
ltpuser->pw_uid);
perror("seteuid");
}
/* Remove the temporary directory */
tst_rmdir();
/*
* print timing stats if that option was specified.
* print errno log if that option was specified.
*/
TEST_CLEANUP;
/* exit with return code appropriate for results */
tst_exit();
}
示例2: cleanup
/*
* cleanup() - performs all the ONE TIME cleanup for this test at completion
* or premature exit.
*/
void cleanup(void)
{
/* if they exist, remove the shared memory resources */
rm_shm(shm_id_1);
rm_shm(shm_id_2);
tst_rmdir();
}
示例3: cleanup
void cleanup(void)
{
rm_shm(shm_id_1);
rm_shm(shm_id_2);
set_sys_tune("nr_hugepages", orig_hugepages, 0);
tst_rmdir();
}
示例4: main
int main(void)
{
int shmid, shmid1;
char *cp, *cp1;
srand48((getpid() << 16) + (unsigned)time(NULL));
key[0] = (key_t) lrand48();
key[1] = (key_t) lrand48();
cp = NULL;
cp1 = NULL;
/*--------------------------------------------------------*/
if ((shmid = shmget(key[0], SIZE, IPC_CREAT | 0666)) < 0) {
perror("shmget");
tst_resm(TFAIL,
"Error: shmget: shmid = %d, errno = %d\n",
shmid, errno);
} else {
cp = shmat(shmid, NULL, 0);
if (cp == (char *)-1) {
tst_resm(TFAIL, "shmat");
rm_shm(shmid);
}
}
tst_resm(TPASS, "shmget & shmat");
/*--------------------------------------------------------*/
if ((shmid1 = shmget(key[1], SIZE, IPC_CREAT | 0666)) < 0) {
perror("shmget2");
tst_resm(TFAIL,
"Error: shmget: shmid1 = %d, errno = %d\n",
shmid1, errno);
} else {
cp1 = shmat(shmid1, cp + (SIZE / 2), 0);
if (cp1 != (char *)-1) {
perror("shmat");
tst_resm(TFAIL,
"Error: shmat: shmid1 = %d, addr= %p, errno = %d\n",
shmid1, cp1, errno);
} else {
tst_resm(TPASS, "2nd shmget & shmat");
}
}
/*------------------------------------------------------*/
rm_shm(shmid);
rm_shm(shmid1);
tst_exit();
}
示例5: main
int main()
{
register int shmid;
char *cp;
key_t key;
errno = 0;
key = (key_t) getpid();
/*----------------------------------------------------------------*/
if ((shmid = shmget(key, 16 * K_1, IPC_CREAT | 0666)) < 0) {
perror("shmget");
tst_resm(TFAIL, "shmget Failed: shmid = %d, errno = %d\n",
shmid, errno);
tst_exit();
}
tst_resm(TPASS, "shmget");
/*----------------------------------------------------------------*/
cp = (char *)shmat(shmid, (void *)NULL, 0);
if (cp == (char *)-1) {
perror("shmat");
tst_resm(TFAIL, "shmat Failed: shmid = %d, errno = %d\n",
shmid, errno);
rm_shm(shmid);
tst_exit();
}
*cp = '1';
*(cp + 1) = '2';
tst_resm(TPASS, "shmat");
/*----------------------------------------------------------------*/
rm_shm(shmid);
if (*cp != '1' || *(cp + 1) != '2') {
tst_resm(TFAIL,
"Error in shared memory contents: shmid = %d\n",
shmid);
}
tst_resm(TPASS, "Correct shared memory contents");
/*------------------------------------------------------------------*/
tst_exit();
/*-------------------- THIS LINE IS NOT REACHED -------------------*/
return (0);
}
示例6: main
int main(void)
{
char *cp=NULL, *cp1=NULL;
int shmid;
key = (key_t) getpid() ;
errno = 0 ;
/*-------------------------------------------------------*/
if ((shmid = shmget(key, 24*K_1, IPC_CREAT|0666)) < 0) {
perror("shmget");
tst_resm(TFAIL,"Error: shmget: shmid = %d, errno = %d\n",
shmid, errno) ;
tst_exit() ;
}
cp = (char *) shmat(shmid, (void *)0, 0);
if (cp == (char *)-1) {
tst_resm(TFAIL,"shmat1 Failed");
rm_shm(shmid) ;
tst_exit() ;
}
cp1 = (char *) shmat(shmid, (void *)0, 0);
if (cp1 == (char *)-1) {
perror("shmat2");
rm_shm(shmid) ;
tst_exit() ;
}
tst_resm(TPASS,"shmget,shmat");
/*--------------------------------------------------------*/
if (shmdt(cp) < 0) {
perror("shmdt2");
tst_resm(TFAIL,"shmdt:cp") ;
}
if (shmdt(cp1) < 0 ) {
perror("shmdt1");
tst_resm(TFAIL,"shmdt:cp1") ;
}
tst_resm(TPASS,"shmdt");
/*---------------------------------------------------------*/
rm_shm(shmid) ;
tst_exit() ;
/*---------------------------------------------------------*/
return(0);
}
示例7: cleanup
/*
* cleanup() - performs all the ONE TIME cleanup for this test at completion
* or premature exit.
*/
void cleanup(void)
{
/* if they exist, remove the shared memory resources */
rm_shm(shm_id_2);
rm_shm(shm_id_3);
tst_rmdir();
/*
* print timing stats if that option was specified.
* print errno log if that option was specified.
*/
TEST_CLEANUP;
}
示例8: main
int main(int ac, char **av)
{
int pid;
void do_child(void);
tst_parse_opts(ac, av, NULL, NULL);
setup(); /* global setup */
if ((pid = FORK_OR_VFORK()) == -1) {
tst_brkm(TBROK, cleanup, "could not fork");
}
if (pid == 0) { /* child */
/* set the user ID of the child to the non root user */
if (setuid(ltp_uid) == -1) {
tst_resm(TBROK, "setuid() failed");
exit(1);
}
do_child();
} else {
/* wait for the child to return */
SAFE_WAITPID(cleanup, pid, NULL, 0);
/* if it exists, remove the shared memory resource */
rm_shm(shm_id_1);
tst_rmdir();
}
cleanup();
tst_exit();
}
示例9: cleanup
/*
* cleanup() - performs all the ONE TIME cleanup for this test at completion
* or premature exit.
*/
void cleanup(void)
{
/* if it exists, remove the shared memory resource */
rm_shm(shm_id_1);
tst_rmdir();
}
示例10: cleanup
void cleanup(void)
{
TEST_CLEANUP;
rm_shm(shmid1);
tst_rmdir();
}
示例11: cleanup
/*
* cleanup() - performs all the ONE TIME cleanup for this test at completion
* or premature exit.
*/
void cleanup(void)
{
/* if they exist, remove the shared memory resources */
rm_shm(shm_id_2);
rm_shm(shm_id_3);
/* Remove the temporary directory */
tst_rmdir();
/*
* print timing stats if that option was specified.
* print errno log if that option was specified.
*/
TEST_CLEANUP;
/* exit with return code appropriate for results */
tst_exit();
}
示例12: cleanup
static void cleanup(void)
{
int i;
for (i = 0; i < num_shms; i++)
rm_shm(shm_id_arr[i]);
FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);
restore_nr_hugepages();
}
示例13: main
int main(int argc, char const *argv[])
{
int i;
int shm_id;
pid_t pid;
char *map_buf1;
char *map_buf2;
shm_id = get_shm(); // 创建一个共享内存段,并返回一个id标识符
pid = fork();
if(pid < 0)
{
perror("Create New Process Error");
exit(EXIT_FAILURE);
}else
if(pid == 0)
{
/*在子进程中*/
map_buf1 = at_shm(shm_id); // 将共享内存段连接到子进程中,并使map_buf1指向共享内存段
i = 0;
while(i < _SHM_SIZE_)
{
map_buf1[i] = '8';
i++;
}
map_buf1[_SHM_SIZE_-1] = '\0';
rm_shm(map_buf1); // 分离子进程与共享内存
}else
{
/*在父进程中*/
map_buf2 = at_shm(shm_id); // 将共享内存连接到父进程中,并使map_buf2指向共享内存段
sleep(5);
printf("In Parent, read Share Memory: %s\n", map_buf2);
rm_shm(map_buf2); // 分离父进程与共享内存
waitpid(pid, NULL, 0); // 等待子进程结束
delete_shm(shm_id); // 删除共享内存
}
return 0;
}
示例14: buf_dtor
void buf_dtor(struct buf_s *buf)
{
if (!buf)
return;
if (buf->mapW) {
detach_shm(buf);
rm_shm(buf);
} else
detach_mal(buf);
}
示例15: cleanup
/*
* cleanup() - performs all the ONE TIME cleanup for this test at completion
* or premature exit.
*/
void cleanup(void)
{
/* if it exists, remove the shared memory segment */
rm_shm(shm_id_1);
tst_rmdir();
/*
* print timing stats if that option was specified.
* print errno log if that option was specified.
*/
TEST_CLEANUP;
}