使用msgget返回-1,errno等于89

内核编译和嵌入式产品的设计与开发
回复
qry
帖子: 8
注册时间: 2017-03-24 10:43
系统: ubuntu14

使用msgget返回-1,errno等于89

#1

帖子 qry » 2017-03-24 10:50

最近需要用到消息队列,代码写完后msgget返回-1,errno等于89,不知道什么原因;下面是部分代码:
INT BMC_MSGQ_Create(VOID)
{
INT iMsgId = 0;

iMsgId = msgget(IPC_PRIVATE, 0666 | IPC_CREAT);
if (-1 == iMsgId)
{
T_E("msgget failed with error: %d", errno);
return iMsgId;
}

return iMsgId;
}
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 使用msgget返回-1,errno等于89

#2

帖子 poloshiao » 2017-03-24 10:54

http://man7.org/linux/man-pages/man2/msgget.2.html
msgget - get a System V message queue identifier

RETURN VALUE
If successful, the return value will be the message queue identifier (a nonnegative integer), otherwise -1 with errno indicating the error.

你確認是 System V ?
https://zh.wikipedia.org/wiki/UNIX_System_V
qry
帖子: 8
注册时间: 2017-03-24 10:43
系统: ubuntu14

Re: 使用msgget返回-1,errno等于89

#3

帖子 qry » 2017-03-24 11:20

poloshiao, 你好,
我这边linux内核是4.4的版本,应该可以用 POSIX 的IPC吧?
qry
帖子: 8
注册时间: 2017-03-24 10:43
系统: ubuntu14

Re: 使用msgget返回-1,errno等于89

#4

帖子 qry » 2017-03-24 11:36

hi,poloshiao,
我代码是跑在linux上的,可以支持system v的IPC啊
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 使用msgget返回-1,errno等于89

#5

帖子 poloshiao » 2017-03-24 14:20

1. 請提供 作業系統 及 版本

2. 把下面指令 複製 貼進終端機 執行
pstree -p | grep "(1)"
把結果 直接 選取/複製 貼上來

3. 把下面指令 複製 貼進終端機 執行
sudo cat /boot/grub/grub.cfg | grep menuentry
把結果 直接 選取/複製 貼上來
qry
帖子: 8
注册时间: 2017-03-24 10:43
系统: ubuntu14

Re: 使用msgget返回-1,errno等于89

#6

帖子 qry » 2017-03-25 14:09

poloshiao, 你好
你说的是这些吗?
root@ubuntu:/# pstree -p | grep "(1)"
init(1)-+-acpid(1174)
root@ubuntu:/#
root@ubuntu:/#
root@ubuntu:/# cat /proc/version
Linux version 3.19.0-25-generic (buildd@lgw01-20) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015
root@ubuntu:/#
root@ubuntu:/# sudo cat /boot/grub/grub.cfg | grep menuentry
if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
menuentry_id_option=""
export menuentry_id_option
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-8f67ea8a-de5d-4f01-8f6b-6eb590d024cd' {
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-8f67ea8a-de5d-4f01-8f6b-6eb590d024cd' {
menuentry 'Ubuntu, with Linux 3.19.0-25-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-25-generic-advanced-8f67ea8a-de5d-4f01-8f6b-6eb590d024cd' {
menuentry 'Ubuntu, with Linux 3.19.0-25-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-25-generic-recovery-8f67ea8a-de5d-4f01-8f6b-6eb590d024cd' {
menuentry 'Memory test (memtest86+)' {
menuentry 'Memory test (memtest86+, serial console 115200)' {
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 使用msgget返回-1,errno等于89

#7

帖子 poloshiao » 2017-03-25 14:48

cat /proc/version
Linux version 3.19.0-25-generic (buildd@lgw01-20) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015
https://wiki.ubuntu.com/TrustyTahr/Rele ... d_Packages
Updated Packages
Linux kernel 3.19
By default, the 14.04.3 point release will ship with a newer 3.19 Linux kernel from Ubuntu 15.04, and a matching X.org stack. This is based on the 3.19.0 Extended Upstream Stable Kernel Release. The purpose of providing a newer kernel in the 14.04.3 point release is for hardware enablement. For more information regarding the 14.04.3 LTS Hardware Enablement Stack, please refer to:
https://wiki.ubuntu.com/TrustyTahr/Rele ... ment_Stack

如果是 Ubuntu 14.04.3
檢查一下 你有沒有安裝
LTS Hardware Enablement Stack
(才能順利使用 Linux kernel 3.19)
qry
帖子: 8
注册时间: 2017-03-24 10:43
系统: ubuntu14

Re: 使用msgget返回-1,errno等于89

#8

帖子 qry » 2017-03-25 15:17

poloshiao,
我是不是直接安装这个通用版:
sudo apt-get install --install-recommends linux-generic-lts-xenial xserver-xorg-core-lts-xenial xserver-xorg-lts-xenial xserver-xorg-video-all-lts-xenial xserver-xorg-input-all-lts-xenial libwayland-egl1-mesa-lts-xenial
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 使用msgget返回-1,errno等于89

#9

帖子 poloshiao » 2017-03-25 16:40

分兩種情況
直接下載 Ubuntu 14.04.2 或者 以後版本 的 ISO 來安裝的 Ubuntu
已經預裝 hardware enablement stack (所以 不須再安裝)
只有從 14.04.0 or 14.04.1 的 ISO 來安裝的 Ubuntu 才需要額外安裝 hardware enablement stack
例如
sudo apt-get install linux-generic-lts-vivid xserver-xorg-lts-vivid libegl1-mesa-drivers-lts-vivid xserver-xorg-video-all-lts-vivid xserver-xorg-input-all-lts-vivid
qry
帖子: 8
注册时间: 2017-03-24 10:43
系统: ubuntu14

Re: 使用msgget返回-1,errno等于89

#10

帖子 qry » 2017-03-25 16:42

如果是 Ubuntu 14.04.3
檢查一下 你有沒有安裝
LTS Hardware Enablement Stack
(才能順利使用 Linux kernel 3.19)[/quote]



root@ubuntu:/opt/mscc# sudo dpkg -l | grep linux-generic-lts
ii linux-generic-lts-vivid 3.19.0.25.12 amd64 Complete Generic Linux kernel and headers
root@ubuntu:/opt/mscc#

我这个需要更新么
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 使用msgget返回-1,errno等于89

#11

帖子 poloshiao » 2017-03-25 16:47

sudo dpkg -l | grep linux-generic-lts
ii linux-generic-lts-vivid 3.19.0.25.12 amd64 Complete Generic Linux kernel and headers
我这个需要更新么
表示已經安裝了 不須額外再安裝
意思是 可以安裝/使用 Ubuntu 15.04 (Vivid Vervet) 以下的 開源驅動及程式
qry
帖子: 8
注册时间: 2017-03-24 10:43
系统: ubuntu14

Re: 使用msgget返回-1,errno等于89

#12

帖子 qry » 2017-03-25 16:57

好的,谢谢你的耐心解答,关于我那个问题我补充一点,就是如果我写一个创建消息队列的test程序然后直接用gcc编译,是可以正常创建msgid的,但我现在的代码需要经过交叉编译后再烧到开发板,板子起来后就会报错:msgget失败,errno=89
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 使用msgget返回-1,errno等于89

#13

帖子 poloshiao » 2017-03-25 17:07

我代码是跑在linux上的,可以支持system v的IPC啊
1. sysvinit 就是 system V 风格的 init 系统
1-1. https://www.ibm.com/developerworks/cn/l ... index.html
sysvinit 就是 system V 风格的 init 系统,顾名思义,它源于 System V 系列 UNIX。
1-2. Upstart 是 第二代 開機初始化程式 (用來 取代 sysvinit 但是可以向後相容 sysvinit)
pstree -p | grep "(1)"
init(1)-+-acpid(1174)
2. init(1) 表示開機初始化程式是 Upstart

3. http://upstart.ubuntu.com/cookbook/
使用
system V
system-v
sysV
關鍵字
搜尋看看 在 Upstart 向後相容 system V 有何注意事項 或說 限制 及 有沒有 設定 需要注意的地方
头像
astolia
论坛版主
帖子: 6396
注册时间: 2008-09-18 13:11

Re: 使用msgget返回-1,errno等于89

#14

帖子 astolia » 2017-08-02 11:37

我建议楼上还是不要来回答这些编程相关的问题了,这在你的知识范围之外。
sysv ipc system call和sysv init有个屁关系。

楼主发到这个版上,那么这段代码应该是用交叉编译跑在嵌入式系统上的?你去检查一下你编译嵌入式系统的时候,是不是裁剪掉了不该去掉的东西?你编译这个程序的时候,相关的头文件和库文件是不是和嵌入式系统用的一样?
回复