C 程序在后台运行时停止执行

C 程序在后台运行时停止执行,c,exec,fork,background-process,C,Exec,Fork,Background Process,我有一个简单的C程序,它在for循环的帮助下使用fork和execl两次运行一个应用程序fleet static。应用程序本身是交互式的,即它使用shell从用户获取输入并打印输出。如果我正常运行程序,就不会出现问题。但是当我从后台运行C程序时,主程序停止了。这是节目单 int main() { int i, pid; for (i=0; i<2; i++) { pid = fork(); if (pid == -1)

我有一个简单的C程序,它在for循环的帮助下使用fork和execl两次运行一个应用程序fleet static。应用程序本身是交互式的,即它使用shell从用户获取输入并打印输出。如果我正常运行程序,就不会出现问题。但是当我从后台运行C程序时,主程序停止了。这是节目单

int main()
{
    int i, pid;
    for (i=0; i<2; i++)
    {
        pid = fork();

        if (pid == -1)
        {
            printf("\nerror, failed to fork()");
        }
        else if (pid > 0)
        {
        }
        else
        {
            /*we are the child*/
            execl("./flute-static", "./flute-static", "-send", "-a192.168.190.1", "/", "6666", "JFlute.1.2.tar.gz", NULL);
            exit(1);
        }
    }

    while(1)
    {
    }
    return 0;
}

为什么会这样?我怎样才能解决这个问题呢?请提供帮助。

您是否从shell获得任何程序输入?当我在shell中运行solo应用程序时,它会自动启动并阻止shell。它需要按“q”按钮停止执行。因为我不想停止它,所以我不会从shell向程序提供任何输入。运行应用程序flute static两次-是吗?我认为它是path和arg0,不是吗?我使用for循环运行了两次。长笛静态文件正在做什么,它是否向sigstop这样的父级传递任何信号。
[root@localhost Flute]# ./a.out&
[3] 2643
[root@localhost Flute]#

[3]+  Stopped                 ./a.out