troubleshooting Question

How to start a program with PHP?

Avatar of djcrackhome
djcrackhomeFlag for Germany asked on
Linux OS DevPHPApache Web Server
8 Comments1 Solution433 ViewsLast Modified:
Hello I complied the Code in the Codebox as with
gcc -static -o
and with Putty it works, but now I would like to start the program with PHP and if I put for example shell_exec or system it works by giving me a PID but I think the arguments or other stuff is wrong, first I tried the same code i use in putty to start it, but this doesn't work with PHP.

Here is the putty start code:
./start /var/www/vhosts/ 7777.conf
But it doesn't work with the PHP Code, I mean the PHP file opens the file correctly otherwise there would not be any PID echo.

But when I check over PS AUX then it is started over webuser but no connection from the sc_trans to sc_serv..... But started it with the same arguments etc over putty works fine.

Best regards
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
    pid_t pid, sid;
    int status;

    if (argc < 3)
        printf("No arg\n");

    if (pid < 0)
        printf("can't fork\n");

    if (pid != 0)
        // Parent
	printf("%d", pid);

    /* Create new session ID */
    sid = setsid();
    if (sid < 0)
        printf("setsid failed");

    /* Close out the standard file descriptors */

    char exec_name[1024];
    snprintf(exec_name, sizeof(exec_name), "%ssc_trans", argv[1]);
    execl(exec_name, exec_name, argv[2], 0);
    /* Never get here */
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros