linux操作系统中 使用系统调用的一般方式是怎样的?

来源:百度知道 编辑:UC知道 时间:2024/05/31 14:20:21
linux操作系统中 使用系统调用的一般方式是怎样的?

给个例子给你看看吧,这里是linux中一个C语言程序,他用到了linux提供的系统调用,很长的程序了,或许你没耐心看,我在最后给你列出那些地方用了系统调用
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>

#define BUFF_LEN 1024
#define RET_ERROR 1
#define RET_OK 0

typedef struct msg_send_struct { //这就是一个消息的数据结构
long my_type; //我们就是根据这个字段来区分每块消息的
char my_text[BUFF_LEN];
} msg_send_struct;

int main() {
char * path = "/";
int i_porject_id = 7;
key_t key;
msg_send_struct msg_send; //定义发送消息

int i_ret;
int i_msg_id;
int i_flag = 0666|IPC_CREAT; //为消息管道的创建指定参数,IPC_CREAT表示这个消息队列是创建,而不是搜索已经存在的消息队列

key = ftok(path, i_porject_id);//为消息队列生成一个key,当然你也可以手动指定,当你运气很好没有和已经窜在的消息队列的key起冲突的时候
if(key == 1) {
prin