基础:systemV 信号 create send recv rmid

阅读更多
/*
@gcc version 3.2.2 20030222
@Linux version 2.4.20-8
*/


/*
@function:create
*/
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

int main(int argc, char **argv)
{
	int c, oflag, mqid;
	key_t keyMsg;
	
	oflag = 0666|IPC_CREAT;
	while( (c=getopt(argc, argv, "e")) != -1 )
	{
		switch(c)
		{
			case 'e':
				oflag |= IPC_EXCL;
				break;	
		}	
	}
	
	if( optind != argc-1 )
	{
		cout<<"usage:msgcreate[-e] "< 
 

/*
@function:send
*/
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

int main(int argc, char **argv)
{
	int mqid, iResult;
	size_t len;
	long type;
	struct msgbuf *ptr;
	
	if(argc != 4)
	{
		cout<<"usage:msgsnd  <#bytes> "<mtype=type;
	
	iResult = msgsnd(mqid, ptr, len, 0);
	if(iResult == -1)
	{
		cout<<"err msgsnd:"< 
 

/*
@function:recv
*/
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

#define MAXMSG (8192+sizeof(long))

int main(int argc, char **argv)
{
	int c, flag, mqid;
	long type;
	ssize_t n;
	struct msgbuf *buff;
	
	type = flag = 0;
	while( (c=getopt(argc, argv, "nt:")) != -1 )
	{
		switch(c)
		{
			case 'n':
				flag |= IPC_NOWAIT;
				break;
			case 't':
				type = atoi(optarg);
				break;	
		}
	}
	
	if( optind != argc-1 )
	{
		cout<<"argc err: usage:msgrcv [-n] [-t type] "<mtype< 
 

/*
@function:rmid
*/
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

int main(int argc, char **argv)
{
	int mqid, iResult;
	
	if(argc != 2)
	{
		cout<<"usage:msgrmid "< 
 

你可能感兴趣的:(C,C++,C#,Linux,GCC)