以下是修改后的enter和serve函数:
```c
void enter(int msgid, int client_id) {
struct message msg;
msg.type = 1;
msg.client_id = client_id;
if (msgsnd(msgid, &msg, sizeof(msg.client_id), 0) == -1) {
perror("msgsnd");
exit(EXIT_FAILURE);
}
}
void serve(int msgid) {
struct message msg;
while (1) {
if (msgrcv(msgid, &msg, sizeof(msg.client_id), 1, 0) == -1) {
perror("msgrcv");
exit(EXIT_FAILURE);
}
printf("Server: received control message from client %d\n", msg.client_id);
}
}
```
在enter函数中,我们创建了一个类型为1的消息,并将client_id存储在其中。然后使用msgsnd函数将该消息发送到服务器进程。
在serve函数中,我们使用msgrcv函数接收类型为1的消息,并从中提取出client_id。然后打印出收到的控制消息。
注意,由于我们将类型1作为控制消息的专用类型,因此在调用msgrcv函数时,第三个参数的值应该为sizeof(msg.client_id),而不是sizeof(struct message)。这是因为我们只需要接收一个整数,而不是整个结构体。优先级的值没有发生变化,仍然是1。