/* Msg Oddajnik */ #include #include #include #include #define MSG_TYPE 1 /* Tip mojih sporocil */ struct MsgSend_t{ long MsgType; long SenderId; char Message[128]; }; int main( argc, argv ) int argc; char **argv; { int MsgId, MsgSendSize; struct MsgSend_t MsgSend; if( argc != 2 ){ printf("Uporaba: %s sporocilo\n", argv[0] ); exit( 1 ); } if( (MsgId = msgget( ftok("msgkey", 'k'), 0644 )) == -1 ){ printf("%s: Napaka, msgget ni uspel\n", argv[0]); exit( 2 ); } MsgSend.MsgType = MSG_TYPE; /* Naj bo tip sporocila tak */ MsgSend.SenderId = getpid( ); /* To naj je moja oznaka */ strcpy( MsgSend.Message, argv[1] ); /* To je sporocilo */ MsgSendSize = sizeof(MsgSend.SenderId) + strlen( argv[1] ); if( msgsnd( MsgId, &MsgSend, MsgSendSize ) == -1 ){ printf("%s: Napaka, msgsnd ni uspel\n", argv[0]); exit( 2 ); } exit( 0 ); }