zsh-users
 help / color / mirror / code / Atom feed
* killed by signal
@ 2009-04-06  8:27 Atom Smasher
  2009-04-06  9:03 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Atom Smasher @ 2009-04-06  8:27 UTC (permalink / raw)
  To: zsh-users

if i understand it correctly... if zsh (or most/all other shells) spawns a 
process that is "terminated" by a signal, the exit status returned (to?) 
by the shell is 128+SIGNAL. but what about processes that are 
stopped/suspended by signals (most likely ^Z, on the command line)? if a 
process is stopped/suspended by a ^Z, is there *any* way for the parent 
shell to figure out if the process was suspended? or to differentiate if 
the return status just happens to be the same as a TSTP signal number?

thanks...


-- 
         ...atom

  ________________________
  http://atom.smasher.org/
  762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
  -------------------------------------------------

 	"A good many observers have remarked that if
 	 equality could come at once the Negro would
 	 not be ready for it. I submit that the
 	 white American is even more unprepared."
 		-- Martin Luther King, Jr.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: killed by signal
  2009-04-06  8:27 killed by signal Atom Smasher
@ 2009-04-06  9:03 ` Peter Stephenson
  2009-04-07  0:58   ` Atom Smasher
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2009-04-06  9:03 UTC (permalink / raw)
  To: zsh-users

On Mon, 6 Apr 2009 20:27:42 +1200 (NZST)
Atom Smasher <atom@smasher.org> wrote:
> if i understand it correctly... if zsh (or most/all other shells) spawns a 
> process that is "terminated" by a signal, the exit status returned (to?) 
> by the shell is 128+SIGNAL. but what about processes that are 
> stopped/suspended by signals (most likely ^Z, on the command line)? if a 
> process is stopped/suspended by a ^Z, is there *any* way for the parent 
> shell to figure out if the process was suspended? or to differentiate if 
> the return status just happens to be the same as a TSTP signal number?

$jobstates (from zsh/parameter) tells you.  If that's not the answer you'll
have to give more details about what you're actually trying to do (which is
often the way to get the most useful results).

% sleep 10 &
[1] 2117
% kill -TSTP %1
[1]  + suspended  sleep 10
% print $jobstates
suspended:+:2117=suspended

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: killed by signal
  2009-04-06  9:03 ` Peter Stephenson
@ 2009-04-07  0:58   ` Atom Smasher
  2009-04-07 10:25     ` Atom Smasher
  0 siblings, 1 reply; 4+ messages in thread
From: Atom Smasher @ 2009-04-07  0:58 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

On Mon, 6 Apr 2009, Peter Stephenson wrote:

> $jobstates (from zsh/parameter) tells you.  If that's not the answer 
> you'll have to give more details about what you're actually trying to do 
> (which is often the way to get the most useful results).
===============

i can use the return status to figure out if a command was "terminated" by 
a signal, and which signal was the killer... 128+9 = 137 == KILL. i know 
the command immediately preceding the precmd was KILLed.

but if a command is suspended (TSTP; 20 on linux, 18 on freebsd) precmd 
will see a return status <128, which could be a "legal" value for a 
command to return indicating a particular failure. i'd like precmd to 
distinguish between a command that returns 18 or 20 (freebsd or linux, 
respectively), and a command that is suspended with ^Z.

specific example... on freebsd i can get a return status of 18 either by 
suspending a job with ^Z, or running:
 	zip -MM foo.zip no-such-file
  so the question is: how can the shell (can the shell?) tell that one of 
those was suspended with a signal (^Z, TSTP), and zip which is indicating 
a specific failure (zip: "File not found").

for a few seconds i thought the ERRNO might be useful, but it seems to not 
be.

thanks...


-- 
         ...atom

  ________________________
  http://atom.smasher.org/
  762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
  -------------------------------------------------

 	"Since trade ignores national boundaries and the manufacturer
 	 insists on having the world as a market, the flag of his
 	 nation must follow him, and the doors of the nations which
 	 are closed against him must be battered down. Concessions
 	 obtained by financiers must be safeguarded by ministers of
 	 state, even if the sovereignty of unwilling nations be
 	 outraged in the process. Colonies must be obtained or
 	 planted, in order that no useful corner of the world may be
 	 overlooked or left unused."
 		-- Woodrow Wilson,
 		President of the United States, 1919


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: killed by signal
  2009-04-07  0:58   ` Atom Smasher
@ 2009-04-07 10:25     ` Atom Smasher
  0 siblings, 0 replies; 4+ messages in thread
From: Atom Smasher @ 2009-04-07 10:25 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

On Tue, 7 Apr 2009, Atom Smasher wrote:

> but if a command is suspended (TSTP; 20 on linux, 18 on freebsd) precmd 
> will see a return status <128, which could be a "legal" value for a 
> command to return indicating a particular failure. i'd like precmd to 
> distinguish between a command that returns 18 or 20 (freebsd or linux, 
> respectively), and a command that is suspended with ^Z.
>
> specific example... on freebsd i can get a return status of 18 either by 
> suspending a job with ^Z, or running:
> 	zip -MM foo.zip no-such-file
>  so the question is: how can the shell (can the shell?) tell that one of 
> those was suspended with a signal (^Z, TSTP), and zip which is 
> indicating a specific failure (zip: "File not found").
=========================

here's a hack.... after a command is suspended, $? is updated but 
$pipestatus isn't. so if
 	[[ ${?} != ${${=pipestatus}[-1]} ]]
  then the preceding command must have been suspended.

but it doesn't work all the time: if a command returns with an exit status 
equal to a suspend signal (which is probably rare), and the next command 
is suspended with that signal, that would result in a false negative; 
failing to detect that a command was suspended... but most of the time it 
should work, and i don't think it's possible to get a false positive.

if anyone has a better way to do it...


-- 
         ...atom

  ________________________
  http://atom.smasher.org/
  762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
  -------------------------------------------------

 	"I spent 33 years in the Marines. Most of my time being a
 	 high-class muscle man for Big business, for Wall Street and
 	 the bankers. In short, I was a racketeer for capitalism. I
 	 helped purify Nicaragua for the international banking house
 	 of Brown Brothers in 1909-1912. I helped make Mexico and
 	 especially Tampico safe for American oil interests in 1914.
 	 I brought light to the Dominican Republic for American sugar
 	 interests in 1916. I helped make Haiti and Cuba a decent
 	 place for the National City Bank boys to collect revenue in.
 	 I helped in the rape of half a dozen Central American
 	 republics for the benefit of Wall Street"
 		-- Smedley D. Butler, (1881-1940)
 		Major Gen U.S. Marines
 		at the time of his death the most
 		decorated U.S. Marine in history


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-04-07 10:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-06  8:27 killed by signal Atom Smasher
2009-04-06  9:03 ` Peter Stephenson
2009-04-07  0:58   ` Atom Smasher
2009-04-07 10:25     ` Atom Smasher

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).