2

I knew how to suspend one process and bring it into foreground in current shell, but I have no idea about that If I have run a process in shell A and now I want to bring it into foreground in current shell B.
Without using third tools like screen, does there exist a way to do this task?
In my opinion, I think it should be suspended and resume it in foreground, however, I don't know how to do.

2

There are usually 2 things you would need to do to get this effect:

  • Reparent the process to a new shell.

    There is basically no way to do this as far as I know. In UNIX, there is only one way to reparent a process that I know about, and that happens only when its original parent dies without waiting for it. In that case the process (an orphan) gets reparented to init, process ID 1. But that doesn't help you here, because you neither want to kill the original parent nor do you want the new parent to become init.

    Anyone (with permission) can still send signals to processes like SIGTSTP and SIGCONT and SIGINT so you can use the kill command to send those signals to the process (or process group) in order to simulate effects like suspending, continuing, and interrupting the job, but the new shell won't be aware of it and won't receive notifications about the status of the process group and therefore cannot track it with its job control feature.

  • Redirect stdio. Because the process' stdio is probably attached to the terminal where the process was started and you probably want to get it to go to the terminal where the new shell is running. Unless you had redirected output to a file or other location originally.

    There do exist some ways to do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.