- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-31-2005 06:43 AM
тАО08-31-2005 06:43 AM
I have a shell script described below:
# limit the number of open file descriptors
resetFd() {
if [ ! -n "`uname -s |grep -i cygwin || uname -s |grep -i windows_nt`" ]
then
maxfiles=`ulimit -H -n`
if [ ! $? -a "${maxfiles}" != 1024 ]; then
if [ "${maxfiles}" = "unlimited" ]; then
maxfiles=1025
fi
if [ "${maxfiles}" -lt 1024 ]; then
ulimit -n ${maxfiles}
else
ulimit -n 1024
fi
fi
fi
}
In the above code what is the meaning of :-
---
maxfiles=`ulimit -H -n`
if [ ! $? -a "${maxfiles}" != 1024 ]; then
if [ "${maxfiles}" = "unlimited" ]; then
maxfiles=1025
fi
---
Also please explain the final outcome of the script.
Thanks,
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-31-2005 07:03 AM
тАО08-31-2005 07:03 AM
SolutionThe script's variable 'maxfiles' is established with:
# maxfiles=`ulimit -H -n`
The HARD limit of the kernel parameter 'maxfiles_lim' is requested with '-H -n' [ see the man pages for sh-posix() ].
If the request was successful and the returned value does not equal 1024 [line-2], then a test is made to see if the returned value is "unlimited" [line-3]. If it is "unlimited" then the script's 'maxfiles' variable is set to 1025.
The script continues and finally sets the SOFT limit to the smaller of 1024 or the value of $maxfiles.
The idea is that the kernel parameter 'maxfiles' is the number of files a process is allowed to have open at any one time. This is called the SOFT limit. This value may be increased by a user, but not beyond the HARD limit.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-31-2005 07:11 AM
тАО08-31-2005 07:11 AM
Re: shell script
In general this code is attempting to test for the ulimit's upper limit. It goes as follows:
maxfiles=`ulimit -H -n` - This sets the maxfiles to the value returned by the command "ulimit -H -n" which will be a numberic value.
if [ ! $? -a "${maxfiles}" != 1024 ]; - This is testing the return code of the previous command ($?) to see if it is not (!) 0. And (-a) the maxfiles returned by "ulimit -H -n" is not 1024 (!= 1024).
if [ "${maxfiles}" = "unlimited" ]; - This checks to see if "ulimit -H -n" returned "unlimited". If the above if and this if are both true, maxfiles will be set to 1025.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-31-2005 07:12 AM
тАО08-31-2005 07:12 AM
Re: shell script
The final result is to set the max number of open file descriptors to a maximum of 1024.
PS- That form of the ulimit command is not only available in the posix shell.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-31-2005 07:14 AM
тАО08-31-2005 07:14 AM
Re: shell script
Meant to say "only available in posix sh"
Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-31-2005 07:16 AM
тАО08-31-2005 07:16 AM
Re: shell script
ulimit -H -n is availabe in sh shell only. If you plan to run it on ksh, then you will have to do /usr/bin/ulimit -H -n