|
发表于 2006-2-7 18:09:30
|
显示全部楼层
这个简单点,但不知道有没有问题。
[code:1]
#include <gtk/gtk.h>
#include <sys/types.h>
#include <unistd.h>
void btn_callback(GtkWidget *widget, gpointer data)
{
pid_t pid;
pid = fork();
if(pid == -1)
exit(-1);
else if(pid ==0)
{
execlp("gtk-demo","gtk-demo",NULL);
}
else
return;
}
main()
{
GtkWidget *win;
GtkWidget *btn;
gtk_init(NULL,NULL);
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
btn = gtk_button_new_with_label("do fork");
gtk_container_add(GTK_CONTAINER(win),btn);
gtk_widget_set_usize(win,300,300);
gtk_widget_show_all(win);
gtk_signal_connect(btn,"clicked",btn_callback,NULL);
gtk_signal_connect(win,"destroy",gtk_main_quit,NULL);
gtk_main();
}
[/code:1] |
|