12.07.2015 Views

RedHawk Linux User's Guide version 6.3 日本語版

RedHawk Linux User's Guide version 6.3 日本語版

RedHawk Linux User's Guide version 6.3 日本語版

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

メッセージ・キュー・プログラム 例/* Create a child process. */child_pid = fork();if (child_pid == (pid_t)-1) {/* The fork(2) call returned an error. */perror(“fork”);/* Remove the message queue. */(void) msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);}exit(-1);if (child_pid == 0) {/* Child process *//* Set the message type. */msg_buffer.mtype = MSGTYPE;/* Perform some work for parent. */sleep(1);/* ... *//* Copy a message into the message buffer structure. */strcpy(msg_buffer.mtext, “Results of work”);/* Send the message to the parent using the message* queue that was inherited at fork(2) time.*/retval = msgsnd(msqid, (const void *)&msg_buffer,strlen(msg_buffer.mtext) + 1, 0);if (retval) {perror(“msgsnd(child)”);/* Remove the message queue. */(void) msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);exit(-1);}/* Send the parent a SIGRT signal. */retval = kill(parent_pid, SIGRT1);if (retval) {perror(“kill SIGRT”);}/* Remove the message queue. */(void) msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);exit(-1);}exit(0);/* Parent *//* Setup to catch the SIGRT signal. The child process* will send a SIGRT signal to the parent after sending* the parent the message.*/sigemptyset(&set);sa.sa_mask = set;sa.sa_sigaction = sighandler;A-5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!