On Sun, 17 Jun 2001, guy keren wrote:
>
> in continuation to the previous post, i made a test that seemed to work
> (at least partially) to regain control of 'ncftp':
>
> 1. in a shell attached to /dev/tty1, i ran 'nohup ncftp'.
> i didn't connect to any server, and then ctrl-Z, 'bg', and 'exit' (had
> to 'exit' twice, since the shell notices there's a suspended process).
> note: the shell i use is 'tcsh'.
>
> 2. opened a shell on '/dev/tty4'.
>
> 3. on a shell attached to '/dev/tty5' i run a debugger:
> gdb /usr/bin/ncftp 7787
>
> in the debugger:
>
> (gdb) print open("/dev/tty4", 0) /* '0' stands for O_RDONLY */
> $ = 4
> (gdb) print dup2(4, 0);
> $ = 0
> (gdb) print open("/dev/tty4", 01) /* '01' stands for O_WRONLY */
> $ = 5
> (gdb) print dup2(5, 1);
> $ = 0
> (gdb) print dup2(5, 2);
> $ = 0
Wait a second - will gdb call functions for me if I do that with print()
and not with its call command? I don't know what to think of this feature.
It could be dangerous because I can mess things with a simple print. But
it's probabably handier than call().
I didn't know that and is it seems I learn something new about gdb
everyday. Seriously
Regards,
Shlomi Fish
There is no IGLU Cabal! All its members are too busy memorizing the gdb
features to be able to continue its acitivities.
> (gdb) set variable stdin = fdopen(0, "r")
> (gdb) set variable stdout = fdopen(1, "a")
> (gdb) set variable stderr = fdopen(2, "a")
> (gdb) quit
> The program is running. Quit anyway (and detach it)? (y or n) y
> Detaching from program: /usr/bin/ncftp, Pid 7787
> > kill -CONT 7787
>
> 4. i switched back to the shell of "/dev/tty4", and typed 'ls' and ENTER.
> then i got a response from ncftp (regarding not being connected to any
> server), and then i got its prompt. i then could continue working with
> it. note that it took over the terminal - i had no way to talk to the
> shell. presisng ctrl-Z just gave a beep. pressing ctrl-C caused ncftp
> to exit, and then i got the shell's prompt.
>
> btw, with 'ftp' - i could make the process remain alive when i closes its
> original shell. apparently, it agrees to remain active only if it's in the
> middle of a file transfer operation.
>
> so, this method seems to work in some way. note that i didn't try leaving
> ncftp backgrounded for a long duration, and i also didn't try to actually
> connect to a server with it (i tried to some invalid address and it gave
> me the normal DNS lookup error, and then i decided to check what ctrl-Z
> and ctrl-C do.... ;) ).
>
> i think this calles for a 'bdetach' and a 'battach' set of shell/perl
> scripts. 'battach' will do what i listed above. 'bedtach' will set a
> termporary tty for the process (attach a debugger to it, open a new pty,
> and set it as stdin for the process, and set /dev/null as stdout and
> stderr for the process) and make it imune to HUP signals.
> it'll be interesting to check this method on the shell itself. if it'll
> work, it'll give a screen-like behaviour without having to run screen in
> advance, or having it installed on the system. any system with a debugger
> on it will work...
>
> --
> guy
>
> "For world domination - press 1,
> or dial 0, and please hold, for the creator." -- nob o. dy
>
>
> =================================================================
> To unsubscribe, send mail to [EMAIL PROTECTED] with
> the word "unsubscribe" in the message body, e.g., run the command
> echo unsubscribe | mail [EMAIL PROTECTED]
>
----------------------------------------------------------------------
Shlomi Fish [EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/
Home E-mail: [EMAIL PROTECTED]
A more experienced programmer does not make less bugs. He just realizes
what went wrong more quickly.
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]