11271

本文展示了一个使用消息队列进行进程间通信的C语言示例程序。该程序包括消息队列的创建、消息发送及接收等关键步骤,并演示了如何通过指定的消息类型来筛选接收到的消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <sys/types.h>
#include <sys/msg.h>
#include <unistd.h>


struct msg_buf
    {
        int mtype;
        char data[255];
    };
 
int main()
{
        key_t key;
        int msgid;
        int ret;
        struct msg_buf msgbuf;
        struct msg_buf msgbuf1;
        struct msg_buf msgbuf2;
        struct msg_buf msgbuf3;
 
        key=ftok("/tmp/2",'a');
        printf("key =[%x]\n",key);
        msgid=msgget(key,IPC_CREAT|0666); /*通过文件对应*/


        if(msgid==-1)
        {
                printf("create error\n");
                return -1;
        }
 
        msgbuf1.mtype = 1;
        strcpy(msgbuf1.data,"test haha1");
        msgbuf2.mtype = 2;
        strcpy(msgbuf2.data,"test haha2");
        msgbuf3.mtype = 3;
        strcpy(msgbuf3.data,"test haha3");


        ret=msgsnd(msgid,&msgbuf1,sizeof(msgbuf1.data),IPC_NOWAIT);
        ret=msgsnd(msgid,&msgbuf2,sizeof(msgbuf2.data),IPC_NOWAIT);
        ret=msgsnd(msgid,&msgbuf3,sizeof(msgbuf3.data),IPC_NOWAIT);
        if(ret==-1)
        {
                printf("send message err\n");
                return -1;
        }
 
        memset(&msgbuf,0,sizeof(msgbuf));
        ret=msgrcv(msgid,&msgbuf,sizeof(msgbuf.data),2,IPC_NOWAIT);
        if(ret==-1)
        {
                printf("recv message err\n");
                return -1;
        }
        printf("recv msg =[%s]\n",msgbuf.data);
 
}
ROS_MASTER_URI=http://localhost:11311 process[abot_driver-1]: started with pid [11227] process[abot_imu-2]: started with pid [11228] process[base_imu_to_base_link-3]: started with pid [11239] process[base_laser_to_base_link-4]: started with pid [11241] process[imu_filter_madgwick-5]: started with pid [11246] process[robot_pose_ekf-6]: started with pid [11250] process[odom_ekf-7]: started with pid [11255] process[joint_state_publisher-8]: started with pid [11266] [ INFO] [1741329298.897535489]: port:/dev/abot buadrate:921600 [ INFO] [1741329298.914410219]: IMU calibration found. process[robot_state_publisher-9]: started with pid [11268] [ INFO] [1741329298.993604768]: Starting ImuFilter process[rplidarNode-10]: started with pid [11271] process[laser_filter-11]: started with pid [11277] [ INFO] [1741329299.126334122]: out_pid_debug_enable:0 [ INFO] [1741329299.228310009]: BaseDriver startup Transport main read/write started [ INFO] [1741329299.231230559]: connected to main board [ INFO] [1741329299.360461609]: Using dt computed from message headers [ INFO] [1741329299.360665780]: The gravity vector is kept in the IMU message. [ INFO] [1741329299.417325997]: Starting Raw Imu Bridge. [ INFO] [1741329299.500850550]: RPLIDAR running on ROS package rplidar_ros. SDK Version:1.7.0 [ INFO] [1741329299.748798455]: Imu filter gain set to 0.100000 [ INFO] [1741329299.749018907]: Gyro drift bias set to 0.000000 [ INFO] [1741329299.749163294]: Magnetometer bias values: 0.000000 0.000000 0.000000 [ INFO] [1741329299.772481628]: output frame: odom [ INFO] [1741329299.847852108]: base frame: base_footprint [ INFO] [1741329299.877294784]: BOX filter started [ INFO] [1741329299.948587655]: invert filter not set, assuming false [ INFO] [1741329301.231547591]: end sleep [ INFO] [1741329301.245752946]: robot version:v1.0.2 build time:20180730-m0e0 [ INFO] [1741329301.264577695]: subscribe cmd topic on [cmd_vel] [ INFO] [1741329301.280285015]: advertise odom topic on [wheel_odom] [ INFO] [1741329301.308485577]: RobotParameters: 97 225 3960 10 320 2700 0 10 250 50 50 250 69 [ INFO] [1741329301.708502447]: Initializing Odom sensor [ WARN] [1741329301.727296527]: Calibrating accelerometer and gyroscope, make sure robot is stationary and level. [ INFO] [1741329301.741557545]: Odom sensor activated [ INFO] [1741329301.742947838]: Kalman filter initialized with odom measurement [INFO] [1741329301.841551]: Publishing combined odometry on [ERROR] [1741329304.043761987]: Error, operation time out. RESULT_OPERATION_TIMEOUT! [rplidarNode-10] process has died [pid 11271, exit code 255, cmd /opt/ros/melodic/lib/rplidar_ros/rplidarNode __name:=rplidarNode __log:=/home/robot/.ros/log/4555c2d8-fb1e-11ef-b86e-982cbceead36/rplidarNode-10.log]. log file: /home/robot/.ros/log/4555c2d8-fb1e-11ef-b86e-982cbceead36/rplidarNode-10*.log [ WARN] [1741329310.035015476]: Still waiting for data on topic /imu/data_raw... [ INFO] [1741329317.897678201]: Calibrating accelerometer and gyroscope complete. [ INFO] [1741329317.897737851]: Bias values can be saved for reuse. [ INFO] [1741329317.897784946]: Accelerometer: x: 0.069855, y: 0.096045, z: -0.577353 [ INFO] [1741329317.897814783]: Gyroscope: x: -0.070678, y: 0.115459, z: -0.012532 [ INFO] [1741329317.932081971]: First IMU message received. [ INFO] [1741329317.932650697]: Initializing Imu sensor [ INFO] [1741329317.996404847]: Imu sensor activated
最新发布
03-08
y x1 x2 x3 x4 x5 1159.93 571.7 4545.6 570 42361 910.9 1175.79 629.89 4891.6 735.3 43725 961 1212.33 700.02 5323.4 771.3 45295 1230.4 1366.95 775.59 5962.7 860.1 46436 1430.1 1642.86 947.35 7208.1 1201 48197 1832.9 2004.82 2040.79 9016 2066.7 49873 2543.2 2122.01 2090.73 10275.2 2580.4 51282 3120.6 2199.35 2140.36 12058.6 3084.2 52783 3791.7 2357.24 2390.47 15042.8 3821.8 54334 4753.8 2664.9 2727.4 16992.3 4155.9 55329 4410.4 2937.1 2821.86 18667.8 5560.1 64749 4517 3149.48 2990.17 21781.5 7225.8 65491 5594.5 3483.37 3296.91 26923.5 9119.6 66152 8080.1 4348.95 4255.3 35333.9 11271 66808 13072.3 5218.1 5126.88 48197.9 20381.9 67455 17042.1 6242.2 6038.04 60793.7 23499.9 68065 20019.3 7407.99 6909.82 71176.6 24133.8 68950 22913.5 8651.14 8234.04 78973 26967.2 69820 24941.1 9875.95 9262.8 84402.3 26857.7 70637 28406.2 11444.08 10682.58 89677.1 29896.3 71394 29854.7 13395.23 12581.51 99214.6 39274.2 72085 32917.7 16386.04 15301.38 109655.2 42183.6 72797 37213.5 18903.64 17636.45 120332.7 51378.2 73280 43499.9 21715.25 20017.31 135822.8 70483.5 73736 55566.61 26396.47 24165.68 159878.3 95539.1 74264 70477.43 31649.29 28778.54 184937.4 116921.8 74647 88773.61 38760.2 34804.35 216314.4 140974 74978 109998.16 51321.78 45621.97 265810.3 166863.7 75321 137323.94 61330.35 54223.79 314045.4 179921.5 75564 172828.4 68518.3 59521.59 340902.8 150648.1 75828 224598.77 83101.51 73210.79 401512.8 201722.1 76105 251683.77 利用这一组数据用逐步回归法进行回归建模,并用par(函数做回归诊断)
05-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值