Disclaimer:
   The following post contains C code for *nix!
   Viewer discretion recommended!

Hi,

I'm back, I couldn't resist you mentioning C, so as
you did, big fault, the code that follows is probably
much better than exec, as an stderr terminal will
still be attached, but anyway:

exec("yourprogramname");

this /should/ work, if it don't then the before exec i
mentioned would work!

#include <sys/types.h>
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>

void get_into_background(void)
{
        pid_t    pid;

        // all the familiar kitchenware!

        pid = fork();
        if(pid != 0)
          exit(0);

        setsid(); // sets out process and group id as
part of the session
                  // but only if the process ain't a leader, hehe

        close(STDIN_FILENO);
        close(STDOUT_FILENO);
        close(STDERR_FILENO);

        // the program shouldn't acquire a terminal

        signal(SIGHUP, SIG_IGN); // incase we get
HUP'd, ignore!

        pid = fork();
        if(pid != 0)
          exit(0);

        chdir("/towhere");
        umask(0);
}
 
void the_actual_exec(void)
{
        char    buffer[1024];
        char    *args[3];

        args[0] = "ls";
        args[1] = "-F";
        args[2] = 0;
        
        execv("/bin/ls", args); // 0 terminated array
        perror("execv"); // as exec dont return nutting
                         // going past exec is an ERROR
}


int main(int argc, char **argv)
{
        get_into_background();
        the_actual_exec();
        return 0;
}

=====
To find out more about me : http://www.geocities.com/mimodit
My bookmarks are available @ http://mukul.free.fr

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to