Operating System - HP-UX
1821984 Members
3327 Online
109638 Solutions
New Discussion юеВ

Xmanager Xterm session not disconnecting

 
jpmigue
New Member

Xmanager Xterm session not disconnecting


I am using Xmanager2 and running Xstart with the following command

/usr/bin/X11/xterm -ls -display $DISPLAY

Now when I do a ps for the newly started session, I get

# ps
PID TTY TIME COMMAND
6846 ttyp1 0:00 ps
6833 ttyp1 0:00 -sh

Yet when I do a w from another session I get

# w
11:15am up 20 days, 17:37, 3 users, load average: 0.05, 0.05, 0.04
User tty login@ idle JCPU PCPU what
root pts/tb 11:06am w
root pts/tc 11:06am 9 /usr/bin/X11/xterm -ls -display 192.168.54.41:0

So I've got two terminals asscoiated with the login and when I exit, the ttyp1 session hangs up but the pts/tb doesn't

Any ideas?

Cheers

James
5 REPLIES 5
spex
Honored Contributor

Re: Xmanager Xterm session not disconnecting

James,

'xterm' is a child process of the shell running on pts/tc (i.e. the shell has been fork()'ed). As such, a 'ps' from within the xterm window will not display the xterm process itself, since it has its own address space, distinct from its parent.

'w', or 'uptime -w', will give the same output from any terminal. In other words, the output from 'w' will be the same whether it is run from your xterm, or from pts/tb. It's a different command from 'ps', and shows who is logged in, and what they are doing. So you're comparing apples and oranges by running 'ps' in one place and 'w' in another.

It sounds like you want to run your xterm with the 'nohup' command:

# nohup /usr/bin/X11/xterm -ls -display $DISPLAY &

That way, when you exit your shell, the xterm (which is its child process) won't be killed.

You may also want to look into running 'xterm' from /etc/inittab.

PCS
jpmigue
New Member

Re: Xmanager Xterm session not disconnecting


Thanks for the response spex but not really what I'm after.

1st I want the process to hang up. Session is logged out so I want all processes associated with the session terminal to hang up. Obviously with two terminals this does not happen.

2nd Surely the process is a child, so hanging up the parent should hang up the child? Why does the child process get a new terminal?

Cheers

James
spex
Honored Contributor

Re: Xmanager Xterm session not disconnecting

James,

'xterm' is a special type of program, because unlike other programs, it creates its own terminal when executed.

Watch what happens:

(from pts/1)
# who
root pts/1 Jun 9 09:51
# ps
PID TTY TIME COMMAND
22218 pts/1 0:00 ps
22195 pts/1 0:00 sh
# xterm &
[1] 22219
# who
root ttyp1 Jun 9 09:53
root pts/1 Jun 9 09:51
# ps -f
UID PID PPID C STIME TTY TIME COMMAND
root 22219 22195 0 09:53:11 pts/1 0:00 xterm
root 22223 22195 3 09:53:46 pts/1 0:00 ps -f
root 22195 22191 0 09:51:16 pts/1 0:00 -sh

So my shell, /usr/bin/sh, has PID 22195, and its child, xterm, has PID 22219. Also notice that xterm's PPID (parent PID) is 22195.

# exit
There are running jobs.
# exit
logout root

So my shell and PID 22195 are gone. Now look at xterm's PPID:

(from xterm@tty1)
# who
root ttyp1 Jun 9 09:53
# ps -ef |grep xterm |grep -v grep
root 22219 1 4 09:53:11 ? 0:00 xterm

So xterm's PPID got reassigned to init, PID 1.

If I understand correctly, you want to kill the xterm when you exit the shell. There are many ways you could do this. One way is run 'jobs' from your shell and look for the JOB NUMBER of xterm. Note that job number is different from PID. Most likely xterm will be job %1. Then do 'kill %1' before exiting the shell (the '%' is very important).

You could add this to the logout trap in your .profile so that it runs automatically upon logout. Or, in cases where more than one job could be running from this shell, you could get the job id with:

jobs |awk '/xterm/{gsub(/\[|\]/,"")}; {print $1}'

Use this in a script and reference the script in the logout trap in .profile.

PCS
jpmigue
New Member

Re: Xmanager Xterm session not disconnecting


Ok cheers

Resolved by selecting connection using REXEC instead of TELNET, therefore xterm is not forked from /bin/sh and the HUP is sent directly to the xterm process

CHeers for your help

James
jpmigue
New Member

Re: Xmanager Xterm session not disconnecting


Ok cheers

Resolved by selecting connection using REXEC instead of TELNET, therefore xterm is not forked from /bin/sh and the HUP is sent directly to the xterm process

Cheers for your help

James