1 |
Bernhard Auzinger posted |
2 |
<200602092009.41427.e0026053@×××××××××××××××××.at>, excerpted below, on |
3 |
Thu, 09 Feb 2006 20:09:41 +0100: |
4 |
|
5 |
> It's funny, Duncan. On the one side you are saving every byte of |
6 |
> cpu-cache. On the other side, you are happy by having forked bashes in |
7 |
> your main memory. But how do you take control about that? I mean, how do |
8 |
> you get the code of your forked bashes away from your cpu cache to have |
9 |
> it free for kernel code? |
10 |
|
11 |
Actually, not all of them fork. I hadn't mentioned it, but most of the |
12 |
single-liners use "exec", so fork the single-line bash script off of my |
13 |
invoking session (so it doesn't close when the command is finished) when I |
14 |
initiate it, then use that same bash script process to run whatever the |
15 |
bash script calls. |
16 |
|
17 |
Similarly, because I initiate X/KDE from the command line rather than |
18 |
using kdm/xdm/whatever, I'd normally have the initiating VC bash instance |
19 |
hanging around, but run a script that starts X/KDE in the background, |
20 |
sleeps for 30 seconds, then disowns everything and exits. (I do it this |
21 |
way rather than executing a forkless exec, for troubleshooting purposes, |
22 |
in case X can't start, and because at some point, I discovered that if the |
23 |
session didn't stick around for a bit, X would stop with it, regardless of |
24 |
the disown.) |
25 |
|
26 |
Likewise, when I sudo from my restricted normal user to my "admin user" |
27 |
(which isn't root, but has unrestricted sudo abilities) I source a script |
28 |
(thereby running the script in my existing user bash process) that execs |
29 |
the sudo, such that I end up without any stacked idle processes taking up |
30 |
resources behind my admin session. When the admin session exits, it |
31 |
either logs me out entirely (at a VC) or closes that konsole tab (if I'm |
32 |
in X and using konsole). |
33 |
|
34 |
That brings up an entirely different layer I have as well. In addition to |
35 |
/l/bin (also available in the traditional /usr/local/bin location, |
36 |
courtesy of a symlink) and /l/sbin, I have /l/sudobin, which contains |
37 |
stub-scripts for most of the ea* and similar root-required scriptlets |
38 |
(naturally ep* doesn't require that, as emerge --pretend doesn't require |
39 |
root), that simply exec sudo their /l/sbin counterparts. That way, for |
40 |
commonly issued emerge and other admin commands, I don't have to directly |
41 |
sudo them from the admin user, only invoke them as I would directly as |
42 |
root. At the same time, I retain protection against an errant rm -rf .* |
43 |
or the like (keeping in mind the consequences of such, due to the .. |
44 |
parent dir entry) as the admin user, and while sudo rm -rf .* would |
45 |
certainly do it, I know that every time I stick sudo in front, as the book |
46 |
"Running Linux" advises, "Sit on your hands a moment and make *VERY* sure |
47 |
the command is what you /think/ it is, and will do what you /expect/ it to |
48 |
and no more, before you hit that enter key." Naturally, these |
49 |
stub-scripts use the source command or exec as well, the result being that |
50 |
sometimes there's a /whole/ /series/ of separate commands operating |
51 |
serially as the same system process, no forking. |
52 |
|
53 |
Of course, Linux' COW (copy on write) memory management scheme ensures |
54 |
that the bash instruction code would remain shared anyway, as Kevin Quinn |
55 |
mentions, but there's still the unique session data to contend with, and |
56 |
in any case, I don't like seeing those stacked processes that are of no |
57 |
further use, hanging around in top/ps/ksysguard/etc, so where possible I |
58 |
eliminate them. |
59 |
|
60 |
-- |
61 |
Duncan - List replies preferred. No HTML msgs. |
62 |
"Every nonfree program has a lord, a master -- |
63 |
and if you use the program, he is your master." Richard Stallman in |
64 |
http://www.linuxdevcenter.com/pub/a/linux/2004/12/22/rms_interview.html |
65 |
|
66 |
|
67 |
-- |
68 |
gentoo-amd64@g.o mailing list |