Re: Passing shell control to another app



On Wed, 27 Sep 2006 08:53:31 +1200, Allistar wrote:

Hi all,
I have an application (developed in C++ and compiled using gcc) that
runs from a shell, to which it outputs quite a bit of information (using
printf).

Part way through the execution of the application it executes another
instance of the same app (using fork followed by execl) and then the
original instance exits. When the original instance exists the user sees
the shell prompt, yet the second instance is still running and still
outputting to the shell.

Is there a way of doing this so that control of the shell is passed to
the second instance?


#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>

extern char **environ;

#define MAX 50
char line[MAX];

int main(int argc, char* argv[], char* env[]){
printf("%s\n", argv[1]);

argv[1] = line;
fgets(line, MAX, stdin);

execve("/home/lars/programming/c/a", argv, env);
perror("after execve");
return 0;}


When running this:


lars@ibmr52:~/programming/c$ gcc -Wall -g a.c -o a && ./a hello
hello
Hei!
Hei!

Hva skjer?
Hva skjer?


--
Lars Rune Nøstdal
http://lars.nostdal.org/

.



Relevant Pages

  • Re: Passing shell control to another app
    ... original instance exits. ... When the original instance exists the user sees ... yet the second instance is still running and still ... outputting to the shell. ...
    (comp.os.linux.development.apps)
  • Passing shell control to another app
    ... the shell prompt, yet the second instance is still running and still ... and to keep the logic flow the same same I want Linux to mimic what Windows ...
    (comp.os.linux.development.apps)