- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
好吧,我正在做一个大学项目,很抱歉提出这个愚蠢的问题。
我的任务是通过消息队列推送一个字符串,派生一个子进程并接收消息,然后通过相同的消息队列将响应发送回父进程,循环执行所有这些操作。
我在家里编写了代码,它工作得很好,但部分任务是让它在大学服务器上工作,这是我遇到的问题。
这是我的代码的相关部分:
父进程:
void fel2()
{
int messq, status;
key_t key = ftok("key", 1);
messq = msgget( key, 0600 | IPC_CREAT );
OpBike * ob_first = NULL;
ob_first = ob_read_in(ob_first);
char confirm_string[64];
while (exists_busy_bike(ob_first))
{
sleep(5);
ob_first = NULL;
ob_first = ob_read_in(ob_first);
int busy_bikes = count_busy_bikes(ob_first);
ob_first = NULL;
srand(time(NULL));
int bret = (rand() % busy_bikes);
ob_first = ob_read_in(ob_first);
ob_first = ob_read_in(ob_first);
int ret_bike_id = get_bikeid_by_jumps(ob_first, bret);
char ret_bike_id_char[64];
snprintf(ret_bike_id_char, 64, "%d", ret_bike_id);
send(messq, ret_bike_id_char);
fel2_child(messq, key);
ob_first = NULL;
wait(NULL);
strcpy(confirm_string, recv(messq));
ob_first = NULL;
ob_first = ob_read_in(ob_first);
wait(NULL);
}
status = msgctl( messq, IPC_RMID, NULL );
wait(NULL);
return;
}
子进程:
int fel2_child(int messq, key_t key)
{
pid_t child = fork();
if (child > 0) // parent process does nothing here
{
}
else { // child
char rbikeid[64];
strcpy(rbikeid, recv(messq));
OpBike * ob_first = NULL;
ob_first = ob_read_in(ob_first);
OpRent * or_first = NULL;
or_first = or_read_in(or_first);
OpBike * bike_ret = get_bike_by_bikeid(ob_first, rbikeid);
char check[64];
strcpy(check, bike_ret->bike_id);
ob_first = NULL;
ob_first = ob_read_in(ob_first);
or_add_return(or_first, ob_first, rbikeid);
ob_first = NULL;
ob_first = ob_read_in(ob_first);
OpBike * bike_check = get_bike_by_bikeid(ob_first, rbikeid);
strcpy(check, bike_check->bike_status);
send(messq, check);
exit(0);
}
return 0;
}
发送方和接收方函数:
int send( int messq, char * text )
{
struct message me = { 119, "asd" };
int status;
strcpy(me.mtext, text);
// THIS IS WHERE EVERYTHING GOES WRONG
status = msgsnd( messq, &me, strlen ( me.mtext ) + 1 , IPC_NOWAIT );
if ( status < 0 )
perror("msgsnd");
return 0;
}
char * recv( int messq)
{
struct message me;
int status;
status = msgrcv(messq, &me, 1024, 119, 0 );
if ( status < 0 )
perror("msgsnd");
char * ret;
ret = malloc(sizeof( char ) * strlen (me.mtext));
strcpy(ret, me.mtext);
return ret;
}
在我家的电脑上运行上面的代码完美无缺。运行 Ubuntu 14.10,我的代码是用 gcc 4.9.1 编译的。但是,它不适用于运行 SLES 11 SP 1 的学校服务器,已使用 gcc 4.3.4 编译了代码。
问题是我尝试发送的字符串没有正确发送。它到达函数,被复制到消息结构中,然后在过程中的某个地方消失,唯一读回的是未定义的数据。
我现在有点没主意了。我已经尝试将消息队列的声明放在其他地方(正如我的教授所建议的),但并没有解决问题。我无法在我学校的服务器上更新编译器,所以这正是我必须处理的。你们中有没有人经历过不同编译器版本的系统调用的奇怪行为?有人知道如何解决这个问题吗?
提前感谢您的回复!
编辑 2: struct message 的定义。
struct message {
long mtype;
char mtext [ 1024 ];
};
最佳答案
好吧,事实证明我的 gcc 版本(或 linux 内核或我使用的任何软件组件)会自动在 ftok 上创建 key 文件(请注意,“ key ”在我的系统上不存在)。然而,大学服务器没有。所以
key_t key = ftok("argv[0]", 1);
或
key_t key = ftok("filename", 1);
成功了。
关于C 系统调用 msgsnd() : invalid argument error on certain compiler versions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27281930/
我正在使用JQuery Mobile,有两个可用版本:稳定版和旧版。我不熟悉后者。 什么是旧版?或与稳定版有什么区别? 建议在生产现场中使用哪一个? 非常感谢 最佳答案 旧版本是一个旧的稳定版本,由于
Lotus Notes 具有“版本控制”功能。您可以将其设置为在用户需要单击 File->New->Version 以创建新版本的模式下工作。我想在表单上的按钮中使用该功能。 有没有办法(使用 Lot
关闭。这个问题是opinion-based 。目前不接受答案。 已关闭10 年前。 已锁定。这个问题及其答案是locked因为这个问题是题外话,但却具有历史意义。目前不接受新的答案或互动。 是否有任何
我对使用数据库和数据库设计/创建模式非常陌生,我非常感谢一些建议/建议。我正在创建一个应用程序,用户在其中输入数据,并向用户提供该数据的版本控制。用户可以进入并恢复更改或更新值(有点像 git)等,我
尝试启动带头 Selenium session 时出现此错误。 我使用的命令是driver = webdriver.Chrome(executable_path=r'C:\Users\Administ
Apple 的文档本来可以更清楚地说明如何提交更新版本。 正如标题所问,有什么区别 itunes connect 中的版本号(提交更新时必须提供) xcode 中的捆绑版本 捆绑版本字符串,短 它们有
当我在我的 Android 设备上运行我的应用程序时出现错误: meteor run android-device --settings settings.json --mobile-server=m
v = data.getValues(XP_PHONE); for (int i = 0; i alter 'table_foo', {NAME => 'column_fam_foo', V
我在Google CoLab中有这样一个错误:。以下是我的Cuda和Torch版本:。CUDA版本:。这是pytorch版本:2.0.1+cu118我试图安装Cuda 11.8,但没有成功。
我从其他用户那里发现了“类似”的问题,但没有一个答案有效。我正在尝试安装这些软件包: if (!require("BiocManager")) install.packages("BiocMana
我正在使用 Version Maven Plugin插件 use-latest-versions将 groupID=com.example* 内部依赖版本更新到最新版本的功能。这是使用 Jenkins
我是 Kotlin 应用程序开发的初学者。当我尝试构建应用程序时发生以下错误 - e: C:/Users/Lenovo/.gradle/caches/transforms-2/files-2.1/32
我正在尝试安装一个名为 metaBIT 的程序。我能够将它添加到我的路径中。但是当我执行时: metaBIT -h 它出错并给我这个: Traceback (most recent call last
在使用选项 -smt2 -in 启动 Z3 后,我可以获取 Z3 的版本吗?有点像 (get-z3-version) ; Z3 4.3.2 x64 // Desired reply 最佳答案 在SM
这个问题在这里已经有了答案: What is the difference between Version and 'Runtime Version' in .Net? (1 个回答) 关闭 9 年
new Version(AssemblyFileVersionAttribute.Version) 总是会成功吗? 这是我的代码。 Contract.Ensures(Contract.Result()
我正在尝试针对另一个使用 libcurl 共享库的共享库 (libtheirstuff.so) 交叉编译我自己的共享库 (libmystuff.so),但出现以下错误: libmystuff.so:
在 Bazaar 中,如果您在 foo.html 中有冲突,它将生成额外的 3 个文件 foo.html.BASE foo.html.OTHER foo.html.THIS 那么你可以 diff -N
我的 java 7 和 java 8 都安装在我的 Windows 系统的 C:\Program Files\Java 下 在环境的路径中我像这样指定了java 7的路径。 %JAVA_HOME%/b
#version 330 和 #version 330 core 有什么区别? 核心重要吗? 最佳答案 这两个版本声明是等价的。 核心 是默认值。来自 GLSL 3.30 规范: If no prof
我是一名优秀的程序员,十分优秀!