HI All,
Looking at porting code from linux and I ran in to the following code block that causes the OS4 system some heart ache:
int ijs_exec_server(const char *server_cmd, int *pfd_to, int *pfd_from, int *pchild_pid) { int fds_to[2], fds_from[2]; int child_pid; if (pipe (fds_to) < 0) return -1; if (pipe (fds_from) < 0) { close (fds_to[0]); close (fds_to[1]); return -1; } child_pid = vfork (); if (child_pid < 0) { close (fds_to[0]); close (fds_to[1]); close (fds_from[0]); close (fds_from[1]); return -1; } if (child_pid == 0) { int status; char *argv[8]; int i = 0; close (fds_to[1]); close (fds_from[0]); dup2 (fds_to[0], STDIN_FILENO); dup2 (fds_from[1], STDOUT_FILENO); #define noGDB #ifdef GDB argv[i++] = "gdb"; #endif argv[i++] = "sh"; argv[i++] = "-c"; argv[i++] = (char *)server_cmd; argv[i++] = NULL; status = execvp (argv[0], argv); if (status < 0) exit (1); }
Anyone have a good example for dealing with pipe,vfork, and execvp?
Thanks!
I don't quite know the point it but it create some pipes, then a thread, to execute a program and pass arguments to it.
You could make your own pipe() if we don't have it with PIPE: I suppose but then you'd need it in the format of the CLib file structure.
We used to have vfork() on 68K which creates a thread wuthout MMU tricks to clone variables, so simpler and more like an Amiga child process but one that can change parent memory.
And execvp() executes a program while passing arguments direct to it.
Whatever it does it might be best to just convert it so it uses Amiga or generic single threaded functions. Or PThreads even.
@tekmage
Compare this with this. It might give you some general idea. If you need anything else, just ask :);
thanks alfkil!
I'll review those files and see how far I can get :)
Cheers,
Bill