3

On my Ubuntu linux computer I'm making a loop like this using my shell bash

HERE MY CODE "./upperscript"

cat filename.txt | while read LINE || [[ -n $LINE ]];
do
    ./script $LINE >> $LINE.txt 2>> $LINE.err & sleep 1
    wait;
done > /dev/null 2>&1 &
echo "[PID $!]"

Here I go

Now, when the script disappears there are a lot of forked process (one at a time) over -bash name like this

username    15029  0.0  0.3   7404  3060 ?        S    mag31   0:00 -bash
username    13849  0.8  0.6  33048  6432 ?        S    mag31   0:08  \_ ./script HERE MY LINE
username    13869  0.1  0.3  33048  6451 ?        S    mag31   0:09    \_ ./otherscript HERE MY LINE
username    13881  0.1  0.1  33048  6465 ?        S    mag31   0:08    \_ ./otherscript HERE MY LINE

how to rename the process with pid 15029 that now it's called simply "-bash"?

I tryed also

$ chmod 777 /proc/15029/comm
chmod: changing permissions of '/proc/15029/comm': Operation not permitted

to do then

echo 'PROCESSNAME' > /proc/15029/comm"

but like u see the error is

"Operation not permitted" also using sudoers username or root (su)

if there's not a way, could I rename it from the process itself?

Saying using

bash -c "exec -a <MyProcessName> <Command>"

in a multiline command like my while?

Thanks a lot

3 Answers3

1

I have the same issue. We can't do this

echo 'PROCESSNAME' > /proc/15029/comm"

It's a question of priviledges

0

Here is an easy way how to achieve what you want:

  1. Put your code in an executable file.
  2. For each fork create a symbolic link to that file.
  3. Execute the symlink instead of the original file.

Reference:

pa4080
  • 30,621
0

A quick demonstation how to use wait:

a_script.sh:

#!/bin/bash
i=5
while ((i--)); do
    $PWD/b_script.sh >> output
    sleep 2
done &
p=$! # because we just have one background
     # process this isn't really necessary.
echo Lets wait for all scripts to end.
read -p \
"meanwhile pick a number, fast! " n && echo you picked: $n
echo back to waiting...
wait $p
echo All done\!

b_script.sh:

#!/bin/bash
echo b_script | ts