C GTK&x2B;系统(3)使用线程调用
我用GTK+-2.0开发了一个简单的应用程序。 我的问题是,如何在不冻结程序的情况下运行bash脚本(例如,使用system(3))? 我试图实现一个线程系统,但没有成功 这是我的代码片段,我尽量简化。 问候C GTK&x2B;系统(3)使用线程调用,c,linux,multithreading,gtk,system,C,Linux,Multithreading,Gtk,System,我用GTK+-2.0开发了一个简单的应用程序。 我的问题是,如何在不冻结程序的情况下运行bash脚本(例如,使用system(3))? 我试图实现一个线程系统,但没有成功 这是我的代码片段,我尽量简化。 问候 尝试分叉进程,并在分叉进程中启动bash脚本 #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main () { int pid; pid = fork();
尝试分叉进程,并在分叉进程中启动bash脚本
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main ()
{
int pid;
pid = fork();
if (pid == 0) {
// Call bash script
} else if (pid > 0) {
// Your parent process
}
return 0;
}
#包括
#包括
#包括
int main()
{
int-pid;
pid=fork();
如果(pid==0){
//调用bash脚本
}否则,如果(pid>0){
//您的父进程
}
返回0;
}
尝试分叉进程,并在分叉进程中启动bash脚本
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main ()
{
int pid;
pid = fork();
if (pid == 0) {
// Call bash script
} else if (pid > 0) {
// Your parent process
}
return 0;
}
#包括
#包括
#包括
int main()
{
int-pid;
pid=fork();
如果(pid==0){
//调用bash脚本
}否则,如果(pid>0){
//您的父进程
}
返回0;
}
不要直接调用fork()
在GTK+应用程序中,最好使用glib。例如,如果您想读取子进程的输出,那么
函数非常方便。不要直接调用fork()
在GTK+应用程序中,最好使用glib。例如,如果您想读取子进程的输出,那么
函数非常方便。谢谢,它似乎可以工作。我在if块中编写了脚本调用,但if块称为父进程时,我应该在else中编写什么呢?谢谢,它似乎可以工作。我在if块中编写了脚本调用,但if块称为父进程时,我应该在else中编写什么呢?