Link to home
Start Free TrialLog in
Avatar of lklm
lklm

asked on

How to bring an orphaned process to foreground ?

Hi.

This is the situation I have.

1. Process "p0" forks (started form terminal).
2. Child "exec"s process "p1"
3. Process "p0" terminates leaving child orphaned.

Now p1 need to read keyboard input. But since it is a background process it can not.

How to solve this ?

Maybe I can bring child to foreground or regain control over terminal ?

Thank You.
Avatar of stefan73
stefan73
Flag of Germany image

Hi lklm,
> Now p1 need to read keyboard input. But since it is a background process
> it can not.

Maybe you can exec in p0 instead of p1?

Cheers,
Stefan
Avatar of lklm
lklm

ASKER

Hi

Unfortunately I can't change the structure of application.
This is multi process application I have access to all the sources but I change change the arch.

Thanks
Not sure if this will work but:

The command "jobs" should show the backgrounded job, if it is still associated with the terminal. If it is job 1 then:
fg %1
should bring it to the foreground.

Might be worth a try.
lklm,
Is p1 really an interactive process? Or do you want to "remote control" its I/O from p0?

Stefan
I am assuming that once p0 terminates, process p1 loses its associated terminal and becomes owned by init.

Is there a reason why you cannot change the point where p0 is forked so that the parent just waits until the child is finished before exiting. Shell programs do this all the time. In your case when you return to your parent, have the parent exit then, instead of after it forks and execs to p1.

Does this make sense?

Anthony.
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial