Hi all. I have some code which does what i need it to do on a standard Linux platform. However i need to make it work on the uClinux kernel, which is used for microcontrollers. To do this, i have been told i will need to change fork() to vfork().
If someone would be able to help me, or guide me on how to make this work on uClinux using the vfork(), i would appreciate it.
Here is the code:
Code:#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> #include <signal.h> void termination_handler(int); int test_pipe=1; int main() { int pipedescriptor[2]; char buff[100]; alarm(10); /*if (signal (SIGALRM, termination_handler) == SIG_IGN)*/ signal (SIGALRM, termination_handler); pipe(pipedescriptor); while (test_pipe>0) { if(!fork()) { printf("This is the child writing to the pipe\n"); write(pipedescriptor[1], "TST", 4); printf("This is the child exiting the pipe\n"); exit(0); } else { printf("This is the parent reading from the pipe\n"); fflush(stdout); read(pipedescriptor[0], buff, 4); printf("Parent reading form pipe: \"%s\"\n", buff); test_pipe++; wait(NULL); } } while(1); return 0; } void termination_handler (int signum) { printf("Total messeges sent: %d\n",test_pipe); printf("Total bytes per second: %d\n",(test_pipe*4)/10); exit(0); }
Any help is appreciated.



LinkBack URL
About LinkBacks



