RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 832997 - ulimit -u does not re-initialize length of bgpids.list
Summary: ulimit -u does not re-initialize length of bgpids.list
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: bash
Version: 6.2
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Roman Rakus
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-06-18 11:18 UTC by Jan Stancek
Modified: 2014-01-13 00:14 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-10-15 11:16:41 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Jan Stancek 2012-06-18 11:18:21 UTC
Description of problem:
ulimit -u has no immediate effect on length of list, which is storing status of background processes. 

Example:
----- cut -----
ulimit -u 1024
cat > /tmp/test.sh <<\EOF
#!/bin/bash
TASKS=4096

ulimit -u 8192
for i in `seq 1 $TASKS`; do
        /bin/sleep 1 &
        PID[$i]=$!
done
sleep 1
for i in `seq 1 $TASKS`; do
        wait ${PID[$i]};
done
EOF
chmod a+x /tmp/test.sh
/tmp/test.sh
----- cut -----

Output is flooded with:
/tmp/test.sh: line 11: wait: pid XXXXX is not a child of this shell

Version-Release number of selected component (if applicable):
bash-4.1.2-3.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
1. run snippet above

Actual results:
bash does not update maximum length of bgpids.list when new value is set via ulimit -u 

Expected results:
ulimit -u should update maximum length of bgpids.list and snippet above should complete without errors

Additional info:

Comment 2 Roman Rakus 2012-06-18 12:07:47 UTC
(In reply to comment #0)
> Description of problem:
> ulimit -u has no immediate effect on length of list, which is storing status
> of background processes. 
> 
> Example:
> ----- cut -----
> ulimit -u 1024
> cat > /tmp/test.sh <<\EOF
> #!/bin/bash
> TASKS=4096
tasks=4096
Better use lowercase variable names
> 
> ulimit -u 8192
> for i in `seq 1 $TASKS`; do
for (( i=1; i<= $tasks; i++)); do
>         /bin/sleep 1 &
>         PID[$i]=$!
> done
> sleep 1
> for i in `seq 1 $TASKS`; do
same as above
>         wait ${PID[$i]};
> done
> EOF
> chmod a+x /tmp/test.sh
> /tmp/test.sh
> ----- cut -----
> 
> Output is flooded with:
> /tmp/test.sh: line 11: wait: pid XXXXX is not a child of this shell
And what do you expect? Child processes ended bevore you call wait on them. You call sleep for 1 second on every child processes. Then you sleep the main process for 1 second, so all (ok, not all of them, but most of them) child processes are done, because they were sleeping for one second also. And then you want to wait for child processes, but most of them already are not existing.
> 
> Version-Release number of selected component (if applicable):
> bash-4.1.2-3.el6.x86_64
> 
> How reproducible:
> 100%
> 
> Steps to Reproduce:
> 1. run snippet above
> 
> Actual results:
> bash does not update maximum length of bgpids.list when new value is set via
> ulimit -u 
> 
> Expected results:
> ulimit -u should update maximum length of bgpids.list and snippet above
> should complete without errors
> 
> Additional info:

[root@RHEL6 ~]# cat t.sh 
#!/bin/bash
ulimit -u
ulimit -u 8192
ulimit -u
[root@RHEL6 ~]# bash t.sh 
1024
8192
[root@RHEL6 ~]# ulimit -u
1024

Comment 3 Jan Stancek 2012-06-18 13:34:22 UTC
(In reply to comment #2)
> And what do you expect? Child processes ended bevore you call wait on them.
> You call sleep for 1 second on every child processes. Then you sleep the
> main process for 1 second, so all (ok, not all of them, but most of them)
> child processes are done, because they were sleeping for one second also.
> And then you want to wait for child processes, but most of them already are
> not existing.

I'm expecting that calling 'wait' on process that has ended should still return exit code, which seems to work fine:
# cp &
[1] 1815
# sleep 5
# wait 1815
# echo $?
1

Anyway, if you insist on starting wait prior to any process being terminated, here is modified example:

----- cut -----
ulimit -u 1024
cat > /tmp/test.sh <<\EOF
#!/bin/bash
tasks=4096

ulimit -u 8192
for (( i=1; i<= $tasks; i++)); do
        /bin/sleep 999 &
        pid[$i]=$!
done
for (( i=1; i<= $tasks; i++)); do
        wait ${pid[$i]};
done
EOF
chmod a+x /tmp/test.sh
/tmp/test.sh &
# wait a bit until all sleeps are started
sleep 10
killall sleep
----- cut -----

Comment 4 Jan Stancek 2012-06-18 14:05:47 UTC
Waiting on all in single wait (as opposed to sequential wait) makes no difference:
----- cut -----
ulimit -u 1024
cat > /tmp/test.sh <<\EOF
#!/bin/bash
tasks=4096

ulimit -u 8192
for (( i=1; i<= $tasks; i++)); do
        /bin/sleep 999 &
        pid[$i]=$!
        all_pids="$all_pids ${pid[i]}"
done
wait $all_pids;
EOF
chmod a+x /tmp/test.sh
/tmp/test.sh &
# wait a bit until all sleeps are started
sleep 10
killall sleep
----- cut -----

Comment 5 Roman Rakus 2012-06-18 15:11:32 UTC
Ah, now I do understand.

I have to find a siutable place to add
js.c_childmax = getmaxchild ();
or so...
Thanks for the report

Comment 7 Roman Rakus 2012-08-22 12:52:13 UTC
One of the reasonable ways is to set up some maximal value. I will prepare patch for it.

Comment 8 Roman Rakus 2012-08-28 07:28:13 UTC
According to the POSIX, it's not reasonable to change system variables and values:
"""
This runtime facility is not meant to provide ever-changing values that applications have to check multiple times. The values are seen as changing no more frequently than once per system initialization, such as by a system administrator or operator with an automatic configuration program. This volume of POSIX.1-2008 specifies that they shall not change within the lifetime of the process.
"""
(from http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html)

I sent a patch upstream which enables posibility to set forced number of remembered statuses.

Comment 9 Roman Rakus 2012-08-28 09:14:25 UTC
Here is the upstream mail with proposed patch:
http://lists.gnu.org/archive/html/bug-bash/2012-08/msg00066.html

Comment 10 Roman Rakus 2012-10-15 11:16:41 UTC
This is not a bug, according to POSIX (see comment #8).


Note You need to log in before you can comment on or make changes to this bug.