当前位置: 技术问答>linux和unix
请问在哪儿能查到shmget返回的错误代码?(100分)
来源: 互联网 发布时间:2016-09-25
本文导语: 我调用shmget失败,errno是20,现在能够确定的是程序没问题,而是环境问题。 系统是Linux | find /usr/include -name "errno.h"|xargs grep 20 还可以在程序中添加perror("shmget"),这样能够显示详细的错误...
我调用shmget失败,errno是20,现在能够确定的是程序没问题,而是环境问题。
系统是Linux
系统是Linux
|
find /usr/include -name "errno.h"|xargs grep 20
还可以在程序中添加perror("shmget"),这样能够显示详细的错误信息。
还可以在程序中添加perror("shmget"),这样能够显示详细的错误信息。
|
man shmget
ERRORS
On failure, errno is set to one of the following:
EACCES The user does not have permission to access the shared memory segment, and does not have the
CAP_IPC_OWNER capability.
EEXIST IPC_CREAT | IPC_EXCL was specified and the segment exists.
EINVAL A new segment was to be created and size SHMMAX, or no new segment was to
be created, a segment with given key existed, but size is greater than the size of that seg-
ment.
ENFILE The system limit on the total number of open files has been reached.
ENOENT No segment exists for the given key, and IPC_CREAT was not specified.
ENOMEM No memory could be allocated for segment overhead.
ENOSPC All possible shared memory IDs have been taken (SHMMNI), or allocating a segment of the
requested size would cause the system to exceed the system-wide limit on shared memory
(SHMALL).
EPERM The SHM_HUGETLB flag was specified, but the caller was not privileged (did not have the
CAP_IPC_LOCK capability).
man ftok
RETURN VALUE
On success the generated key_t value is returned. On failure -1 is returned, with errno indicating the
error as for the stat(2) system call.
man 2 stat
ERRORS
EACCES Search permission is denied for one of the directories in the path prefix of path. (See also
path_resolution(2).)
EBADF filedes is bad.
EFAULT Bad address.
ELOOP Too many symbolic links encountered while traversing the path.
ENAMETOOLONG
File name too long.
ENOENT A component of the path path does not exist, or the path is an empty string.
ENOMEM Out of memory (i.e. kernel memory).
ENOTDIR
A component of the path is not a directory.
可见你的错误不是shmget引起的, 因为shmget本般并不会返回ENOTDIR的错误 而是ftok引起的.
|
man shmget
ERRORS
On failure, errno is set to one of the following:
EACCES The user does not have permission to access the shared memory segment, and does not have the
CAP_IPC_OWNER capability.
EEXIST IPC_CREAT | IPC_EXCL was specified and the segment exists.
EINVAL A new segment was to be created and size SHMMAX, or no new segment was to
be created, a segment with given key existed, but size is greater than the size of that seg-
ment.
ENFILE The system limit on the total number of open files has been reached.
ENOENT No segment exists for the given key, and IPC_CREAT was not specified.
ENOMEM No memory could be allocated for segment overhead.
ENOSPC All possible shared memory IDs have been taken (SHMMNI), or allocating a segment of the
requested size would cause the system to exceed the system-wide limit on shared memory
(SHMALL).
EPERM The SHM_HUGETLB flag was specified, but the caller was not privileged (did not have the
CAP_IPC_LOCK capability).
man ftok
RETURN VALUE
On success the generated key_t value is returned. On failure -1 is returned, with errno indicating the
error as for the stat(2) system call.
man 2 stat
ERRORS
EACCES Search permission is denied for one of the directories in the path prefix of path. (See also
path_resolution(2).)
EBADF filedes is bad.
EFAULT Bad address.
ELOOP Too many symbolic links encountered while traversing the path.
ENAMETOOLONG
File name too long.
ENOENT A component of the path path does not exist, or the path is an empty string.
ENOMEM Out of memory (i.e. kernel memory).
ENOTDIR
A component of the path is not a directory.
ERRORS
On failure, errno is set to one of the following:
EACCES The user does not have permission to access the shared memory segment, and does not have the
CAP_IPC_OWNER capability.
EEXIST IPC_CREAT | IPC_EXCL was specified and the segment exists.
EINVAL A new segment was to be created and size SHMMAX, or no new segment was to
be created, a segment with given key existed, but size is greater than the size of that seg-
ment.
ENFILE The system limit on the total number of open files has been reached.
ENOENT No segment exists for the given key, and IPC_CREAT was not specified.
ENOMEM No memory could be allocated for segment overhead.
ENOSPC All possible shared memory IDs have been taken (SHMMNI), or allocating a segment of the
requested size would cause the system to exceed the system-wide limit on shared memory
(SHMALL).
EPERM The SHM_HUGETLB flag was specified, but the caller was not privileged (did not have the
CAP_IPC_LOCK capability).
man ftok
RETURN VALUE
On success the generated key_t value is returned. On failure -1 is returned, with errno indicating the
error as for the stat(2) system call.
man 2 stat
ERRORS
EACCES Search permission is denied for one of the directories in the path prefix of path. (See also
path_resolution(2).)
EBADF filedes is bad.
EFAULT Bad address.
ELOOP Too many symbolic links encountered while traversing the path.
ENAMETOOLONG
File name too long.
ENOENT A component of the path path does not exist, or the path is an empty string.
ENOMEM Out of memory (i.e. kernel memory).
ENOTDIR
A component of the path is not a directory.
|
使用函数strerror(errno)获取可读取的错误编码
|
看看权限是否够