zsh-users
 help / color / mirror / code / Atom feed
* zsh functions not playing nice.
@ 2013-01-19 16:58 Ray Andrews
  2013-01-19 17:38 ` Stephane Chazelas
  2013-01-19 17:51 ` Russell Harmon
  0 siblings, 2 replies; 4+ messages in thread
From: Ray Andrews @ 2013-01-19 16:58 UTC (permalink / raw)
  To: zsh-users

Gentlemen,

I can't get this sort of thing to work:

     $ nice -n 20 some-zsh-function

returns:

    "nice: some-zsh-function: No such file or directory.

I can use 'nice' with any builtin or binary or script, just not with a 
function.
How do I solve that?

Thanks.


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

* Re: zsh functions not playing nice.
  2013-01-19 16:58 zsh functions not playing nice Ray Andrews
@ 2013-01-19 17:38 ` Stephane Chazelas
  2013-01-19 18:53   ` Ray Andrews
  2013-01-19 17:51 ` Russell Harmon
  1 sibling, 1 reply; 4+ messages in thread
From: Stephane Chazelas @ 2013-01-19 17:38 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

2013-01-19 08:58:23 -0800, Ray Andrews:
> Gentlemen,
> 
> I can't get this sort of thing to work:
> 
>     $ nice -n 20 some-zsh-function
> 
> returns:
> 
>    "nice: some-zsh-function: No such file or directory.
> 
> I can use 'nice' with any builtin or binary or script, just not with
> a function.
> How do I solve that?
[...]

~$ type nice
nice is /usr/bin/nice

There's no way it can know about a zsh function which is
something internal to the shell.

It *executes* a command. So what you think is a builtin is
the command version of it in /bin or /usr/bin:

~$ strace -fe execve nice echo test
execve("/bin/echo", ["echo", "test"], [/* 40 vars */]) = 0

What you could do is:

some-zsh-function & renice $!; fg

Note that it would run that function in a subshell.

-- 
Stephane


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

* Re: zsh functions not playing nice.
  2013-01-19 16:58 zsh functions not playing nice Ray Andrews
  2013-01-19 17:38 ` Stephane Chazelas
@ 2013-01-19 17:51 ` Russell Harmon
  1 sibling, 0 replies; 4+ messages in thread
From: Russell Harmon @ 2013-01-19 17:51 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 753 bytes --]

Unfortunately, this is not possible.

nice can only work on a per-process granularity, as it sets attributes of
the affected process. Builtins and functions are run within the existing
ZSH process.

Scripts and binaries however, if run outside the existing ZSH process (e.g.
not using the "source" builtin), can be niced, and should just work the way
you wrote.
--
Russell Harmon


On Sat, Jan 19, 2013 at 11:58 AM, Ray Andrews <rayandrews@eastlink.ca>wrote:

> Gentlemen,
>
> I can't get this sort of thing to work:
>
>     $ nice -n 20 some-zsh-function
>
> returns:
>
>    "nice: some-zsh-function: No such file or directory.
>
> I can use 'nice' with any builtin or binary or script, just not with a
> function.
> How do I solve that?
>
> Thanks.
>

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

* Re: zsh functions not playing nice.
  2013-01-19 17:38 ` Stephane Chazelas
@ 2013-01-19 18:53   ` Ray Andrews
  0 siblings, 0 replies; 4+ messages in thread
From: Ray Andrews @ 2013-01-19 18:53 UTC (permalink / raw)
  To: zsh-users

On 19/01/13 09:38 AM, Stephane Chazelas wrote:


Thanks. This is a bit over my head but I get some idea.
>
> ~$ type nice
> nice is /usr/bin/nice
>
> There's no way it can know about a zsh function which is
> something internal to the shell.
>
> It *executes* a command. So what you think is a builtin is
> the command version of it in /bin or /usr/bin:
Yes, so I see.
> ~$ strace -fe execve nice echo test
> execve("/bin/echo", ["echo", "test"], [/* 40 vars */]) = 0
>
> What you could do is:
>
> some-zsh-function & renice $!; fg
>
> Note that it would run that function in a subshell.
>
What I'm experimenting with is some way to get consistent run times for
various functions that I'm writing, so as to optimize them. It's quite 
educational.
But the runtimes vary hugely so it's hard to say if any given change has 
had a
positive effect.  I was thinking that if I set the niceness to maximum,
then maybe the times would smooth out since other processes would be 
less likely to
interfere.

Looking at the above, what I'm now doing is just:

   renice -n -20 -u root

... and then just running the function normally. It sure makes things go 
faster,
and it does smooth the runtimes out a bit, tho not perfectly.


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

end of thread, other threads:[~2013-01-19 19:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-19 16:58 zsh functions not playing nice Ray Andrews
2013-01-19 17:38 ` Stephane Chazelas
2013-01-19 18:53   ` Ray Andrews
2013-01-19 17:51 ` Russell Harmon

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).