23,128
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <mqueue.h>
#include <sys/msg.h>
#include <sys/ipc.h>
#define SVMSG_MODE 420
void
err_quit(const char *s)
{
printf("%s\n", s);
exit(1);
}
int
main(int argc, char **argv)
{
int mqid;
size_t len;
long type;
struct msgbuf *ptr;
if (argc != 4)
err_quit("usage: msgsnd <pathname> <#bytes> <type>");
len = atoi(argv[2]);
type = atoi(argv[3]);
mqid = msgget(ftok(argv[1], 0), 288);
ptr = calloc(sizeof(long) + len, sizeof(char));
ptr->mtype = type;
msgsnd(mqid, ptr, len, 0);
exit(0);
}
#include <stdio.h>
#include <alloca.h>
struct student
{
char name[20];
int id;
};
#ifdef TEACHER
struct teacher
{
char name[20];
int id;
};
#endif
int main(void)
{
struct student stuA={"Li Lei",1};
struct teacher *techpa=alloca(sizeof(char)*20+sizeof(int));
struct teacher Kong={"Kong qiu",1};
strcpy(techpa->name,"Mrs. Gao");
techpa->id=2;
return 0;
}
ptr = (struct msgbuf *)calloc(sizeof(long) + len, sizeof(char));
ptr->mtype = type;