- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Strange "ksh" problem
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
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
тАО11-24-2004 01:52 AM
тАО11-24-2004 01:52 AM
There's a loop in the shell script(attachment is the whole script):
# Run the precostcalc program in parallel each processing a supplier
# This line is commented & next line added by Indranil ------cat $SUPPLIERS | while read supplier
while read supplier
do
if [ `jobs | wc -l` -lt $SLOTS ]
then
(
precostcalc $CONNECT $supplier $ADDL_OPTIONS || touch $failed;
) &
else
# Loop until a thread becomes available
while [ `jobs | wc -l` -ge $SLOTS ]
do
: # Null command
done
(
precostcalc $CONNECT $supplier $ADDL_OPTIONS || touch $failed;
) &
fi
I found that such loop never stop (endless loop !) until I pressed "Ctrl+C", which resulted:
Pid 20983 received a SIGSEGV for stack growth failure.
Possible causes: insufficient memory or swap space,
or stack size exceeded maxssiz.
Memory fault(coredump)
because `jobs | wc -l` always 1 and $SLOTS = 1, that's why the loop cannot stop.
But if I change the 1st line of the script from "#! /usr/bin/ksh" to "#! /usr/bin/sh", that is, to use the "sh" instead of "ksh", the vaule of `jobs | wc -l` can change to 0 after several circles which stops the loop !
What difference of "ksh" and "sh" makes this happened ? Do they have different way to handle multi-thread ? or something else ?
I have applied the latest patch for "ksh": PHCO_30316, but the loop still cannot be stopped.
Any suggestion for me?
Thanks a lot !
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 06:18 AM
тАО11-24-2004 06:18 AM
Re: Strange "ksh" problem
Could anyone reply my ticket ?
Problem with "ksh" and "sh"...
Thanks !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 06:39 AM
тАО11-24-2004 06:39 AM
Re: Strange "ksh" problem
set -x
near the top but not at the top.
Also, you should NEVER use ksh to do looping like that without sleeps because you are hammering your machine if all of the "slots are full" with senseless executions/forks/pipes. Add a sleep or change your precostcalc program to initate multiple instances.
live free or die
harry d brown jr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 08:16 PM
тАО11-24-2004 08:16 PM
Re: Strange "ksh" problem
execute_a_command &
pid=$!
wait ${pid}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 11:52 PM
тАО11-24-2004 11:52 PM
Re: Strange "ksh" problem
it might have to do with the use of "||", as e.g. described in Document id: KBRC00005490
http://www5.itrc.hp.com/service/cki/docDisplay.do?docLocale=en_US&docId=200000062907544
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-25-2004 03:39 AM
тАО11-25-2004 03:39 AM
Re: Strange "ksh" problem
Yes, you are right, adding "sleep" into the loop can solve the problem, and yesterday I found that even one or two "echo" into the loop can help, I think it just made millisecond "sleep", incredible !
Why??
Why such sleep makes that difference ? Why the "sh"(bsh) doesn't have this issue but "ksh" does !?
Thanks again !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-25-2004 05:11 AM
тАО11-25-2004 05:11 AM
Re: Strange "ksh" problem
Thanks for your reply !
I read "ksh: handles $? and || command separator differently to sh" from your link that you mentioned, but I don't understand the solution for my case. I don't use "$?" in my script. Could you please tell me details about what I should change? Thanks!
# Run the precostcalc program in parallel each processing a supplier
# This line is commented & next line added by Indranil ------cat $SUPPLIERS | while read supplier
while read supplier
do
if [ `jobs | wc -l` -lt $SLOTS ]
then
(
precostcalc $CONNECT $supplier $ADDL_OPTIONS || touch $failed;
) &
else
# Loop until a thread becomes available
while [ `jobs | wc -l` -ge $SLOTS ]
do
: # Null command
done
(
precostcalc $CONNECT $supplier $ADDL_OPTIONS || touch $failed;
) &
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-25-2004 07:15 AM
тАО11-25-2004 07:15 AM
Re: Strange "ksh" problem
But I have 2 remarks:
1. add a sleep, as already suggested by Harry.
2. Assuming $SLOTS is more or less static, you can remove the then part of the if-construction (and so the whole if-construction) yielding:
while read supplier
do
# Loop until a thread becomes available
while [ `jobs | wc -l` -ge $SLOTS ]
do
sleep 1
done
(
precostcalc $CONNECT $supplier $ADDL_OPTIONS || touch $failed;
) &
By the way, jobs is a shell built in command. Maybe that's something else to consider.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-25-2004 07:44 AM
тАО11-25-2004 07:44 AM
Re: Strange "ksh" problem
I am still hoping that someone can tell me what difference between "ksh" and "sh" made this happen. Because if I don't have any problem to run it with "sh", but I get endless loop when I run it with "ksh"...
I hope I don't need to change the source code because it's another company wrote that code and they said the other clients don't have problem to run the script with "ksh"...
Yes, Jeroen, I suspected "jobs" as well because when I used "set -x" on the top, I could trace the value of "`jobs | wc -l`", and they had different numbers between "ksh" and "sh"...
Thanks again !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-25-2004 11:17 PM
тАО11-25-2004 11:17 PM
Re: Strange "ksh" problem
sorry about my first posting; I did not see that you had posted the whole script - and after reading that it I am painfully aware, that the problem has nothing to do with "||".
I think that the following doc describes your situation concerning putting processes in a subshell in the background, but unfortunately, does not suggest any solution.
Document id: A1456085
http://www5.itrc.hp.com/service/cki/docDisplay.do?docLocale=en_US&docId=200000006352554
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2004 01:46 AM
тАО11-26-2004 01:46 AM
Re: Strange "ksh" problem
Anyone else can help me to find out the reason for this case ?
Why does the "ksh" work fine if I put some "echo"s or a "sleep" inside the loop, it can work like running as "sh" ?
Thanks again !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2004 01:50 AM
тАО11-26-2004 01:50 AM
Re: Strange "ksh" problem
You said "you should NEVER use ksh to do looping like that without sleeps because you are hammering your machine if all of the "slots are full" with senseless executions/forks/pipes." in your post, I thought you might know the "substaintial" reason for this, and some differences between "ksh" and "sh"...
I am waiting for your response... Thanks !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2004 02:18 AM
тАО11-26-2004 02:18 AM
Re: Strange "ksh" problem
"ksh is a command programming language"
In fact Ksh is a bit more complex, offers more feature, but is a little bit more heavy. So it takes more time to launch and initiate, and uses more memory.
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2004 02:49 AM
тАО11-26-2004 02:49 AM
Re: Strange "ksh" problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2004 03:08 AM
тАО11-26-2004 03:08 AM
Re: Strange "ksh" problem
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2004 12:40 AM
тАО11-27-2004 12:40 AM
SolutionI think that the reason why the loop works in ksh when inserting a sleep command is that the sleep command simply prevents the script from using 100% of the cpu resources; without the sleep command inserted, the script may *hammer etc.* and prevent any other process from getting any resources and thus prevent them from finishing. My argument is then that the sleep command makes it possible for other processes to finish, therefore enabling the script itself eventually to finish.
However, I still think that the jobs command in ksh cannot *see* the jobs, as these are launched in a sub-shell. So what I'm saying is actually that it is rather accidental that the script at all stops when using ksh.
(And the reason why it works in sh without sleep is that sh can see the jobs).
But perhaps other members can set me right.
Regards,
John K.