由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
CS版 - Re: very archaic issue : (转载)
相关主题
[请教]:关于马达控制器某些老黑的道德品质那是钢钢的
CENTURYLINK 的猫Q1000只有PWR显示 GREEN, DSL 都不亮是否猫坏 (转载)How to debug "broken pipe" in linux programming ? (转载)
Paper help!网络编程如何进行错误处理
twitter陈光诚呼吁全球联手对中共施压ZT路透社
哪位大牛推荐一本C++的书?李文亮彻底评反了,训诫李文亮的警察要被处罚了
local = (char *(*)()) inc_1; 是啥意思?谷歌创始人Brin敦促奥巴马政府强硬对待中国 痛批微软
Re: very archaic issue : (转载)陈冠希称身为中国人感到骄傲 被疑已是加拿大籍
very archaic issue :蒙古为什么仇华?为什么一蹶不振?
相关话题的讨论汇总
话题: tmp话题: sig话题: trap话题: echo话题: ssh
进入CS版参与讨论
1 (共1页)
c******n
发帖数: 4965
1
【 以下文字转载自 Java 讨论区 】
发信人: creation (努力自由泳50m/45sec !), 信区: Java
标 题: Re: very archaic issue :
发信站: BBS 未名空间站 (Fri Apr 29 11:58:14 2011, 美东)
one colleague replied
using ssh -t ....
would help
here is my reply to him (his approach partially works, but only when you
terminate ssh client by ctrl-C, which is SIGINT, it does not work
when the ssh is run by a daemon like hudson, and terminated with -15 )
######################################
This is a cleaner way than the hack I came up with: I found that “normally
” the remote code terminates because it wants to print to the terminal,
Which is closed after ssh is closed, so the remote code gets itself a
SIGPIPE. Java somehow carefully avoided the SIGPIPE generation OR ignores
sigpipe,
So it never terminates. My hack was to , as soon as the remote shell starts
, I fire off a sub process to continuously spit out something onto the
STDOUT,
So that this subprocess will be given a sigpipe when ssh closes, and that
subprocess (bash process) traps SIGPIPE and in the sig handler, it sends a
kill to the
Pgid, so that all children of the remote shell are killed, including java.
This is a hard kill with -9
Your “-t” approach does work if I do a “ctrl-C” on the client side,
because ssh behavior is to transport the ctrl-C to remote side, which then
pretty much acts like
A normal tty. But in our particular case, the Hudson job sends a “15” to
kill the Hudson process, so ssh still lingers on.
You can test it with following code a.sh
virtual-machine:~$ cat a.sh
rm /tmp/sig
trap "echo HUP >> /tmp/sig " HUP
trap "echo INT >> /tmp/sig " INT
trap "echo ALRM >> /tmp/sig " ALRM
trap "echo PIPE >> /tmp/sig " PIPE
trap "echo POLL >> /tmp/sig " POLL
trap "echo PROF >> /tmp/sig " PROF
trap "echo TERM >> /tmp/sig " TERM
trap "echo USR >> /tmp/sig " USR
trap "echo USR >> /tmp/sig " USR
trap "echo VTALRM >> /tmp/sig " VTALRM
trap "echo STKFLT >> /tmp/sig " STKFLT
trap "echo PWR >> /tmp/sig " PWR
trap "echo WINCH >> /tmp/sig " WINCH
trap "echo CHLD >> /tmp/sig " CHLD
trap "echo URG >> /tmp/sig " URG
trap "echo TSTP >> /tmp/sig " TSTP
trap "echo TTIN >> /tmp/sig " TTIN
trap "echo TTOU >> /tmp/sig " TTOU
trap "echo STOP >> /tmp/sig " STOP
trap "echo CONT >> /tmp/sig " CONT
trap "echo ABRT >> /tmp/sig " ABRT
trap "echo FPE >> /tmp/sig " FPE
trap "echo ILL >> /tmp/sig " ILL
trap "echo QUIT >> /tmp/sig " QUIT
trap "echo SEGV >> /tmp/sig " SEGV
trap "echo TRAP >> /tmp/sig " TRAP
trap "echo SYS >> /tmp/sig " SYS
trap "echo EMT >> /tmp/sig " EMT
trap "echo BUS >> /tmp/sig " BUS
trap "echo XCPU >> /tmp/sig " XCPU
java -cp .:/tmp/tt.jar TestLog4j
TestLog4j code is a simple dead loop that continuously does Log.info(“
something”)
Run command with
Ssh localhost ‘./a.sh’
Then on the client side, kill the ssh process by “kill -15 your_ssh_pid “,
but the remote bash and java is still running
The funny thing that I don’t understand now is, in the above test, after I
killed the ssh client, I DON’T see the /tmp/sig being generated,
But after I manually kill the java process, and the remote bash terminates,
I can see /tmp/sig being generated, containing the content:
HUP
CONT
This confirms my understanding that a terminated ssh –t would give the
remote side a HUP, but why is the signal cached so long ??? and why is there
a CONT ???
Or does the HUP have nothing to do with ssh ? maybe when the remote bash
terminates, it wants to use the terminal, and only now does it gets a HUP
from the OS ???
1 (共1页)
进入CS版参与讨论
相关主题
蒙古为什么仇华?为什么一蹶不振?哪位大牛推荐一本C++的书?
看了扶正照片,真是火死了local = (char *(*)()) inc_1; 是啥意思?
书home computer上的Word过期了Re: very archaic issue : (转载)
office 2019才15块钱very archaic issue :
[请教]:关于马达控制器某些老黑的道德品质那是钢钢的
CENTURYLINK 的猫Q1000只有PWR显示 GREEN, DSL 都不亮是否猫坏 (转载)How to debug "broken pipe" in linux programming ? (转载)
Paper help!网络编程如何进行错误处理
twitter陈光诚呼吁全球联手对中共施压ZT路透社
相关话题的讨论汇总
话题: tmp话题: sig话题: trap话题: echo话题: ssh