请问Photon里面可不可以创建进程?如果可以创建,应该如何创建?在abmain.c文件中的main()函数里面创建,还是在callback函数里面创建?
敬请指教,不胜感激!
创建进程用spawn*()函数,和在不在Photon里面无关。
我用fork()函数创建了一个子进程:可出现了一些问题,望指教!
代码如下:
start_callback( PtWiget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo)
{
pid_t pid;
int i;
/*eliminate “unreferenced” warnings /
widget = widget; apinfo = apinfo; cbinfo = cbinfo;
/ create a child proce */
pid = fork();
if ( pid == 0 )
if (pid == 0)
{
child_proc ();
exit( 0 );
}
for ( i = 0; i<10; i++)
{
PtTerminalPuts ( ABW_terminal, “this is the parent\r\n”);
}
return ( Pt_CONTINUE);
}
void child_proc ( )
{
int i;
for ( i = 0; i<10; i++)
{
PtTerminalPuts ( ABW_terminal, “this is the child\r\n”);
}
}
当我运行这个程序时,只能在PtTerminal中显示this is the parent. 更为不明白的是,当我连着按start这个按钮时,当按到第五次的时候,在在PtTerminal中显示出了this is the child.再反复按,一直都是this is the child.了。
当我在if (pid == 0)
{
child_proc ();
exit( 0 );
}中去掉exit( 0 );再运行时,只能在PtTerminal中显示this is the child.
按道理,在创建了子进程child_proc后,应该在PtTerminal中既显示this is the child.又会显示this is the parent.的。可为什么会出现上述的这些情况呢?
请xtang先生多多指点。谢谢!
xtang先生:我很想知道问题的答案,有空告诉我,可以吗?