bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Feature request: process title with exec -a "" for oneself


From: Chet Ramey
Subject: Re: Feature request: process title with exec -a "" for oneself
Date: Tue, 10 Sep 2024 11:27:05 -0400
User-agent: Mozilla Thunderbird

On 9/5/24 8:37 PM, Lockywolf wrote:

Chet Ramey <chet.ramey@case.edu> writes:

So I assume that you want to change the kernel's idea of the process
arguments as seen and displayed by `ps'. If so, I'm not really interested
in adding that as a feature. It doesn't seem to add anything for shell
users.

Well, I am a shell user :).

Indeed, that is true.


I would really love to have such a feature because I have two use-cases
for it.

1. I would use it as a super minimalist progress indicator for one-shot
scrips written with little consideration.

For example, I sometimes find myself writing something like:
`while true; do try_something_slow && exit 0 ; sleep 1 ; done &`

With a setproctitle I would write something like:

`I=0 ; while true; do try_something_slow && exit 0 ; I=$((I + 1)) ;
setproctitle "trier_$I-times" sleep 1 ; done &`

And this leaves no lingering files, does not require finding a PID to
look at `/proc/$pid/environ`, et cetera. I can just query the progress
using `ps`.

You could just as easily have a function write to your terminal window's
title bar.


2. I would use it to distinguish subshells from the current script in
`ps`.

By default a subshell has the same name as the parent shell.
So when I run `ps/pgrep`, I often get processes with the same name, and
I'd have to parse the output of `pstree` to find out which is which.
And running exec -a "${BASH_ARGV0}_child" while true ; do sleep 1 ; done &
is not a valid syntax.

exec -a "${BASH_ARGV0}_child" bash -c 'while true ; do sleep 1 ; done &'

or put the command in a shell script.


I think this is appropriate for a loadable builtin. This one is Linux-
specific.

I am not experienced enough to have an opinion on whether a loadable
built-in is better than a feature of "exec".

It's more of a per-user opt-in that doesn't require changes to the shell.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]