Altera_Forum
Honored Contributor
19 years agocan't work as my think
Hi hippo.
In a cgi program,I want to use one process to sent HTML page to answer IE as quickly as possible, and another process to execute local control. And they are happend almost at the same time after pressing the button. I used the child process to sent HTML page. and father process to execute local control. I thought when child process exited, the HTML page would display on the IE. The fact is the HTML page will not be displayed untill child and father process both exit. because local control may need long time, I want it to be executed at the background. and the HTML page should be sent quickly. follow is cgi source code:/* Creates two threads, one printing 10000 "a"s, the other printing
10000 "b"s.
Illustrates: thread creation, thread joining. */
# include <unistd.h># include <stddef.h># include <stdio.h># include <stdlib.h># include <sys/types.h># include <sys/wait.h>
//#include "pthread.h"# include "nios2_system.h"
int hex2sev(int hex)
{
unsigned int segments = {
0x81, 0xCF, 0x92, 0x86, 0xCC, 0xA4, 0xA0, 0x8F, 0x80, 0x84, /* 0-9 */
//0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, /* 0-9 */
0x88, 0xE0, 0xF2, 0xC2, 0xB0, 0xB8 /* a-f */
};
//unsigned int data = (segments<<8)+segments;
unsigned int data = segments | (segments << 8);
return data;
}
int main(void)
{
pid_t PID;
int count = 2;
PID = vfork();
/*if(PID == -1)
{
perror("fork failed!\n");
exit(1);
}*/
if(PID == 0)
{
execlp("/bin/sentHTML","");
}
else
{
wait(NULL);
na_seven_seg_pio->np_piodirection=0xffff;
while(count<=50)
{
na_seven_seg_pio->np_piodata=hex2sev(count);
sleep(1);
count++;
}
exit(0);
}
} the sentHTML source code is : #include <stdio.h>
int main(void)
{
printf("Content-type: text/html\n\n");
printf("<html>\n");
printf("<head><title>from child pthread !</title></head>\n");
printf("<body>\n");
printf("<h1>Hello, world.</h1>\n");
//printf("Starting process %s\n", (char *) arg);
printf("</body>\n");
printf("</html>\n");
} They are just a version of main. I have tried lots of ways,such as place sent HTML function in the father process . the result is the same. The HTML page still be sent when both processes exit. please tell me? How to complete my goal. my goal is: one process sent HTML page as quickly as possible; another process do the local control. Thank you!!