Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A QuizKindly log in to use this feature. We’ll take you to the login page automatically.
LoginGeneral Tech Bugs & Fixes 3 years ago
User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Kindly log in to use this feature. We’ll take you to the login page automatically.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
manpreet
Best Answer
3 years ago
I have a shell script that uses a single variable as an associative array (one
KEY=VALUEper line).Throughout the execution of the script, the variable is manipulated to add, remove or modify entries:
Append:
Modify:
Remove:
When executed in a terminal (or as a service on an old machine under sysv through an init script), the script runs fine, but when run as a service under systemd, after a while, the script starts to spit out error messages in the log :
sh: printf: I/O errorAfter a lot of trial and error, I couldn't determine exactly what command(s) in the script produced those errors, but I noticed that they start to appear when the length of the variable reaches 8000 bytes (I guess 8192, but I couldn't pinpoint it exactly since whole lines are appended).
I'm pretty sure the variable length is the problem because I implemented a routine that trims the oldest entries of the array whenever the variable length approaches 8192 bytes, and now the script does run under
systemdfor a long time without errors; but that's of course not ideal, as there is some information lost.I searched the web for information about maximum variable length in shell scripts, but didn't find anything useful :
dashmanual page doesn't say anything about maximum variable length.GNU sed documentation says:
...but this applies to line length, not to the whole text length (the individual lines don't exceed 80 characters)
Anyway, since the errors appear only when the script is run through
systemd, I tried to increaseLimitMSGQUEUEand/orLimitSTACKin the unit file, to no avail (this was a blind guess, as I don't understand exactly the concepts of message queues or process stack, but the numbers shown bysystemctl showlooked like 8 KB or so). All other limits regarding memory (LimitRSS,LimitAS,LimitMEMLOCK) seem high enough (way past 8192 bytes), so I don't know what to do next.What can I do to get this script running under
systemdwithout errors when the variable length exceeds 8 KB ?