30 lines
		
	
	
		
			625 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			625 B
		
	
	
	
		
			C
		
	
	
	
	
	
| #include <sys/types.h>
 | |
| #include <sys/ipc.h>
 | |
| #include <sys/msg.h>
 | |
| #include <stdio.h>
 | |
| #include <stdlib.h>
 | |
| 
 | |
| // 测试 msgctl ,用于删除消息队列
 | |
| int main()
 | |
| {
 | |
|     key_t key = ftok("/", 65);                 // 使用ftok函数生成一个唯一的键值
 | |
|     int msqid = msgget(key, 0666 | IPC_CREAT); // 创建或获取消息队列
 | |
| 
 | |
|     if (msqid == -1)
 | |
|     {
 | |
|         perror("msgget");
 | |
|         exit(1);
 | |
|     }
 | |
| 
 | |
|     // 控制操作:删除消息队列
 | |
|     if (msgctl(msqid, IPC_RMID, NULL) == -1)
 | |
|     {
 | |
|         perror("msgctl");
 | |
|         exit(1);
 | |
|     }
 | |
| 
 | |
|     printf("Message queue removed successfully.\n");
 | |
| 
 | |
|     return 0;
 | |
| }
 |