Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

can'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!!

8 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by sdhnain@Jun 3 2006, 06:38 AM

    hi zzh,

    i think there is a simple solution :

    execute the tasks sequentialy : first display the html page, and then do your local control. i don&#39;t understand why do u want to use two process. http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/rolleyes.gif

    best regards

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=15821)

    --- quote end ---

    --- Quote End ---

    because after press the button, sent HTML page and local control should be executed almost at the same time.How do you execute two tasks sequentialy by a action?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    --- Quote Start ---

    hi zzh,

    almost at the same time.How do you execute two tasks sequentialy by a action?

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=15822)</div>

    --- Quote End ---

    by writing there code sequentialy !

    if you want multitasking it&#39;s better to use an RTOS rather than µClinux,

    with an RTOS u can create tasks and assign them preorities, then the job is done by the scheduler.

    good luck
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by sdhnain@Jun 3 2006, 07:12 AM

    by writing there code sequentialy !

    if you want multitasking it&#39;s better to use an rtos rather than µclinux,

    with an rtos u can create tasks and assign them preorities, then the job is done by the scheduler.

    good luck

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=15823)

    --- quote end ---

    --- Quote End ---

    I want to complete it based on uclinux and it can be done with uclinux. I just don&#39;t know how to.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by zzh+jun 3 2006, 01:34 pm--><div class='quotetop'>quote (zzh @ jun 3 2006, 01:34 pm)</div>

    --- quote start ---

    <!--quotebegin-sdhnain@Jun 3 2006, 07:12 AM

    by writing there code sequentialy !

    if you want multitasking it&#39;s better to use an rtos rather than µclinux,

    with an rtos u can create tasks and assign them preorities, then the job is done by the scheduler.

    good luck

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=15823)

    --- quote end ---

    --- Quote End ---

    I want to complete it based on uclinux and it can be done with uclinux. I just don&#39;t know how to.

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=15825)</div>

    [/b]

    --- Quote End ---

    ok ok,

    u want to let the IE user know that a button was pressed, and at the same time service the interuption,

    well, as I had understand, the HTML response take no significant time.

    ok, to overcome the problem with child and parent process, try this :

    <div class='quotetop'>QUOTE </div>

    --- Quote Start ---

    write a c code that do controls, compile it to produce a .exe and put it in /bin folder to be know as a commande lets say "control.exe".

    in your cgi script invok the control code by the C primitive system :

    system("control");

    and then write your HTML response code.[/b]

    --- Quote End ---

    I think with this method the control.exe will execute in the background.

    but I still don&#39;t understand why it won&#39;t work with process http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/blink.gif

    best regards http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/biggrin.gif
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by sdhnain@Jun 3 2006, 10:05 AM

    ok ok,

    u want to let the ie user know that a button was pressed, and at the same time service the interuption,

    well, as i had understand, the html response take no significant time.

    ok, to overcome the problem with child and parent process, try this :

    write a c code that do controls, compile it to produce a .exe and put it in /bin folder to be know as a commande lets say "control.exe".

    in your cgi script invok the control code by the c primitive system :

    system("control");

    and then write your html response code.

    i think with this method the control.exe will execute in the background.

    but i still don&#39;t understand why it won&#39;t work with process http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/blink.gif

    best regards http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/biggrin.gif

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=15840)

    --- quote end ---

    --- Quote End ---

    I tried what you said and had the same result. Maybe there are some things special to develop cgi progrm. what should I do? really don&#39;t understand why HTML page can&#39;t be sent out after the one process exit.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    There is a AP note for boa cgi, AN3238 from freescale.

    Is it helpful?

    Or you can let the cgi send to FIFO (or IPC etc) to another app process which run the led.