Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: timeout problem in ssh sessions
- X-seq: zsh-users 12627
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: ZSH User List <zsh-users@xxxxxxxxxx>
- Subject: Re: timeout problem in ssh sessions
- Date: Tue, 19 Feb 2008 12:03:46 -0800
- In-reply-to: <20080219102057.GA30154@xxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <27b8b8a0802130621x47568c7fo304848d02a1c6e76@xxxxxxxxxxxxxx> <20080213143803.GI619@xxxxxxxxxxxxxxxxxxx> <20080214125415.GC31852@xxxxxxxxx> <20080214180818.GO619@xxxxxxxxxxxxxxxxxxx> <20080215103220.GF31852@xxxxxxxxx> <080215123047.ZM29728@xxxxxxxxxxxxxxxxxxxxxx> <20080215221834.GA23684@xxxxxxxxx> <080215192616.ZM30010@xxxxxxxxxxxxxxxxxxxxxx> <20080218102729.GA21288@xxxxxxxxx> <080219003557.ZM16257@xxxxxxxxxxxxxxxxxxxxxx> <20080219102057.GA30154@xxxxxxxxx>
On Feb 19, 11:20am, Andy Spiegl wrote:
}
} > schaefer<506> ps="$(ps -eo pid,ppid,cmd)"
} > schaefer<507> print -l "PID: $$" "PPID: $PPID" ${(M)${(f)ps}:#*ps -eo*}
} > PID: 16182
} > PPID: 7139
} > 16255 16254 ps -eo pid,ppid,cmd
}
} Strange, here it's different:
}
} condor:~>ps="$(ps -eo pid,ppid,cmd)"
} condor:~>print -l "PID: $$" "PPID: $PPID" ${(M)${(f)ps}:#*ps -eo*}
} PID: 23435
} PPID: 23388
} 30571 23435 ps -eo pid,ppid,cmd
Hmm ... aha.
* Do we need to fork? We need to fork if:
* 1) The command is supposed to run in the background. (or)
* 2) There is no `exec' flag, and either:
* a) This is a builtin or shell function with output piped somewhere.
* b) This is an external command and we can't do a `fake exec'.
*
* A `fake exec' is possible if we have all the following conditions:
* 1) last1 flag is 1. This indicates that the current shell will not
* be needed after the current command. This is typically the case
* when when the command is the last stage in a subshell, or is the
* last command after the option `-c'.
* 2) We don't have any traps set.
* 3) We don't have any files to delete.
I have a TRAPALRM function, so condition (2) for "fake exec" fails and the
$(...) subshell forks before running "ps".
Zsh is pretty darned clever about this, as even the following doesn't
manage to force an additional fork:
ps="$(<=(ps -eo pid,ppid,cmd))"
However, this does the trick:
ps="$(<<(ps -eo pid,ppid,cmd))"
I'm not sure whether to assert that's "better" than:
ps="$(fgrep -v "pid,ppid" =(ps -eo pid,ppid,cmd))"
In my case, with a trap set, the fgrep formulation results in two extra
forks (one in each subshell) so I suspect $(<<(...)) is preferable.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author