Skip to content
Tcl Source Code Artifact [a7699a56bc]
Login

Artifact [a7699a56bc]

Artifact a7699a56bc9eac02e11f6060b32bc035fe09c7e0:

Ticket change [a7699a56bc] - Ticket [550646ffffffffff|550646ffff] <i>exec (fork) from huge process fails</i> status still Open with 4 other changes by davidlallen on 2002-04-30 23:34:41.
D 2002-04-30T23:34:41
J icomment Logged\sIn:\sYES\s\nuser_id=530697\n\nExcerpts\sfrom\sdiscussion\son\scomp.lang.tcl\sthread\s"Unix\nforking\serror\sencountered",\smid-April\s2002:\n\nI\swrote:\n\n>\sHere's\ssomething\syou\scan\stry.\s\sTake\syour\sfavorite\n>\stclsh\sand\sadd\sa\scommand\swith\sthis\sC\scode.\s\s(Yes,\sI\n>\sknow\sthis\scommand\sleaks\smemory.\s\sThat's\sthe\spoint\s:-)\n>\n>\s\s\s\sint\si;\svoid\s*p;\n>\s\s\s\sfor\s(i=0;\si<512;\si++)\sp\s=\smalloc(1024*1024);\n>\n>\sEach\stime\syou\scall\sit,\sit\sincreases\sthe\svirtual\n>\smemory\ssize\sof\syour\sprocess\sby\s512MB.\s\sNow,\sin\syour\n>\stcl\sshell,\scall\sthis\suntil\sthe\svirtual\smemory\ssize\sof\n>\syour\sprocess\sis\sgreater\sthan\syour\sremaining\sfree\n>\svirtual\smemory.\n>\n>\sThen\s"exec\sls",\sand\syou\swill\sget\sthe\sout\sof\smemory\n>\smessage.\n>\n>\sWhat\sI'm\shoping\sto\sfind\sis\sa\sway\sto\srun\s"ls"\sor\sother\n>\ssimilar\sunix\scommands\swhen\smy\svirtual\smemory\ssize\sis\n>\slarger\sthan\sthe\sfree\svirtual\smemory.\n\nDan\sSmart\s([email protected])\swrote:\n\n>\s>\s>\s[...]\show\sabout:\svfork(),\sthen\swithout\sdiddling\n>\s>\s>\sany\ssignal\shandlers\simmediately\sexec()\sa\snew\n>\s>\s>\stclsh\swith\scommand\sline\sarguments\stelling\sit\sthat\n>\s>\s>\sit's\scompleting\sa\svfork/exec\ssequence\sso\sit\scan\n>\s>\s>\stweak\sthe\ssignal\shandlers\swhere\sthey're\ssupposed\n>\s>\s>\sto\sbe\sin\sthe\schild?\n>\s>\n>\s>\sReferring\sto\sthe\stcl\s8.3.3\ssource\scode,\s"fork()"\n>\s>\sappears\sonly\sonce,\sin\sunix/tclUnixPipe.c,\sfunction\n>\s>\sTclpCreateProcess.\s\sAfter\sfork()'ing,\sthe\schild\n>\s>\sprocess\scode\s(pid\s==\s0\smeans\schild\sprocess)\n>\s>\sexecutes\sRestoreSignals()\sbefore\sexecvp()'ing.\n>\s>\n>\s>\sBased\son\smy\slimited\sunderstanding,\sit\sseems\sto\sme\n>\s>\sthat\sthe\scode\salready\sdoes\swhat\syou\ssuggest.\n>\s>\n>\s>\sI\sthink\sthat\sline\sof\sthe\stcl\ssource\scode\scould\sbe\n>\s>\schanged\sto\suse\svfork()\sinstead\sof\sfork()\sand\smy\sVM\n>\s>\sproblem\swould\sgo\saway\swith\sno\sside\seffects.\n>\s>\n>\s>\sAm\sI\smissing\ssomething?\n>\n>\sYes,\san\sextra\sexec.\n>\n>\sDoing\sanything\swith\ssignal\shandlers\sin\sthe\schild\n>\sbranch\sof\sa\svfork\sis\snot\sa\sgood\sidea,\sin\sfact\sdoing\n>\sanything\sother\sthan\san\sexec\sis\spretty\smuch\sfrowned\n>\supon.\sIf\syou\swant\sto\suse\svfork(),\syou\shave\sto\sreplace\n>\sthe\scurrent\sprocess\simage\s(i.e.\sthe\scopy\sthat\sis\sthe\n>\schild),\swith\sa\snew\sprocess\simage.\sThe\snew\sprocess\n>\simage\scan\sthen\smess\swith\sits\senvironment\sin\sanyway\sit\n>\schooses,\sincluding\schange\ssignal\shandling,\smess\swith\n>\sfile\sdescriptors...\s\sThus\sto\sreplace\sfork()\swith\n>\svfork(),\syou\sneed\san\sintermediate\sprocess,\sthat\stakes\n>\sthe\sdesired\seventual\scommand\sline,\ssets\sup\sa\s"sane\n>\senvironment",\sand\sthen\sexecs\sthe\sfinal\sprocess.\sThe\n>\sdefinition\sof\s"sane\senvironment"\swould\salso\shave\sto\n>\sbe\spassed\sto\sthe\sintermediate.\n>\n>\sPeter's\ssuggestion\swas\sthat\sthe\sintermediate\sprocess\n>\salso\sbe\san\sincarnation\sof\stclsh,\swith\sa\smagic\sflag\sto\n>\stell\sit\sto\sperform\sthe\sabove\sfunction.\sIn\sother\swords\n>\sthe\scurrent\s(pseudoTCL):\n>\n>\s\s\s\s\s\s\s\s\sif\s{[fork]\s==\s0}\s{\n>\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sRestoreSignals\n>\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sexec\smyProgram\sand\san\sarg\n>\s\s\s\s\s\s\s\s\s}\n>\n>\swould\sbecome\s(more\spseudoTCL)\n>\n>\s\s\s\s\s\s\s\s\sif\s{[vfork]\s==\s0}\s{\n>\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sexec\s"tclsh\s-magic\smyProgram\sand\san\sarg"\n>\s\s\s\s\s\s\s\s\s}\n>\n>\sand\stclsh\swould\sinclude\sthe\sfollowing\s(even\smore\n>\spseudoTCL)\n>\n>\s\s\s\s\s\s\s\s\sif\s{[string\sequal\s[lindex\sargv\s0]\s"-magic"]}\s{\n>\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\seval\s[lreplace\s$argv\s0\s0\sexec]\n>\s\s\s\s\s\s\s\s\s}\n>\n>\sNote\sthat\sthis\sdoes\snot\sinclude\spassing\sthe\snecessary\n>\scontext\sinformation\sto\sactually\srestore\sthe\ssignal\n>\shandlers\s(we\sneed\sto\sset\sthem\sto\swhatever\sthe\n>\soriginal\stclsh\sinherited\sfrom\sits\sparent,\srather\sthan\n>\sjust\sto\sdefault).\n\n
J login davidlallen
J mimetype text/plain
J username davidlallen
K 550646ffffffffffffffffffffffffffffffffff
U davidlallen
Z ccdfe5ca36d05d06687f48178a1eff80