Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detach child process to another virtual terminal #151

Open
nataraj-hates-MS-for-stealing-github opened this issue Mar 22, 2024 · 2 comments

Comments

@nataraj-hates-MS-for-stealing-github
Copy link

nataraj-hates-MS-for-stealing-github commented Mar 22, 2024

I do want to use reptyr, so I can fork current process and put it into separate window of tmux terminal. But I still did not find any way how I can do that.
I wrote sample script:

#!/usr/bin/perl
use strict;
use POSIX;

my $pid = fork();

if ($pid)
{ 
  print "$pid\n";
  sleep 10;
  while (1) {print ".\n"; sleep 1};
} else
{
  my $i=0;
  (setsid() != -1)           || die "Can't start a new session: $!";
  sleep 10;
  while (1) {print "$i\n"; sleep 1; $i++};
}

I am trying to reptyr child to another terminal using pid it prints at the beginning, but I get

[-] Timed out waiting for child stop.

Adding -T does not help either.

Have you any idea how I can do that?

@nataraj-hates-MS-for-stealing-github
Copy link
Author

nataraj-hates-MS-for-stealing-github commented Apr 23, 2024

I tried another approach, and it worked. Instead of putting child into new session, as I've done in the example above, I make it it's own group. And that worked for me:

#!/usr/bin/perl

use strict;
use POSIX;

my $pid = fork();
if ($pid)
{ 
  print "$pid\n";
  sleep 10;
  while (1) {print ".\n"; sleep 1};
} else
{
  my $i=0;
   (setpgid($$,$$) != -1)           || die "Can't create own group: $!";
  sleep 10;
  while (1) {print "$i\n"; sleep 1; $i++};
}

and then

reptyr [process id printed by the script above]

in another terminal

@nataraj-hates-MS-for-stealing-github

But problems, I guess. still remains:

  1. It should be good to be able to detach child without doing any magic with group pid and session pid, just out of box
  2. Detaching process that is his own session is also valid case, I guess. It whould be better if it worked to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant