2001 07 12


                    LINUX NEWS
        RESOURCES & LINKS FROM BRAINBUZZ.COM
               Thursday, July 12, 2001
     Read By Over 6,000 Linux Enthusiasts Weekly!


TABLE OF CONTENTS

1) Sean’s Notes

2) Linux News

Caldera OpenLinux to Require Licencing
CerfBoard
Interview with a PHP Developer
Microsoft to Allow Some Rebranding in XP

3) Linux Resources

HTTP Benchmarking
Security Manuals
SNMP FAQ
PostgreSQL Book
XPilot Newbie Guide

4) App o’ the week

~~~~~~~~~~~~~~~~~~~~~~ ADVERTISEMENT ~~~~~~~~~~~~~~~~~~~~~~~

XML is the wave of the Future. Make sure you’re ready to take advantage of the Skills needed in today’s competitive market. FirstClass Systems offers superior XML training presented online with mentoring. Online Training is the most intelligent way to learn anything!

http://ad.brainbuzz.com/?RC06&AI345







For information on how to advertise in this newsletter
please contact mailto:adsales@BrainBuzz.com or visit
http://cramsession.brainbuzz.com/marketing/default.asp

-------------------------
1) Sean's Notes
-------------------------
One of the fundamentals of UNIX is how processes are created.
Sure, we know init does all the dirty work, but how do
processes themselves call for new processes?  If you're
running a web server you'll see that there are a bunch of
httpd processes going, but you only started one of them.
Likewise, inetd (or xinetd) can fire off your ftp server if
a connection comes in.

Well, folks, it's all done through the fork() system call.
Fork, like the name implies, denotes a split of paths.
A simple example (fork1.c) will illustrate (or confuse):

int main(void) {
	printf("Hello (%d)\n", getpid());
	fork();
	printf("Goodbye (%d)\n", getpid());
}

Remember from a previous article that the main function is
where everything starts.  We're going to print out "Hello"
along with our processid.  Then we call fork(), and then
another silly message along with the PID.  Should be simple,
eh?

$ gcc fork1.c -o fork1
$ ./fork1
Hello (3169)
Goodbye (3169)
Goodbye (3170)

Huh?  I only told it to print out Goodbye once!  Look at the
PID, though.  The first and second are from different
processes.  The fork() actually returns twice, but after
creating a second process.  3169 is the parent process, 3170
is the child process.

So if fork() returns twice, what kind of value does it
return?  Here is fork2.c:

#include <sys/types.h>
#include <unistd.h>
int main(void) {
	pid_t pid;
	printf("My pid is %d\n", getpid());
	pid = fork();
	printf("Fork returned %d in pid %d\n", pid, getpid());
}

The differences here are that I included a couple of files
that  the man page for fork() recommended.  This gets me the
pid_t type which stores the result of a fork().  I then
captured the return value of the system call, and printed it
out along with the PID.

$ gcc fork2.c -o fork2
$ ./fork2
My pid is 3235
Fork returned 3236 in pid 3235
Fork returned 0 in pid 3236

Now this is pretty interesting.  The parent (3235) was given
the PID of its child (3236).  The child was given a big fat
zero.  But this isn't a problem, because a child can always
find its parent with getppid(), but it is difficult for a
parent to find all its children.

Now, on to the practical part of the whole exercise.  Forks
are generally used as worker tasks.  Client server programming
is helpful in systems administration, you can write a quick
little daemon that waits around for connections and does some
small tasks.  When the connection comes in, you don't want the
process to be busy until the work is done, you want to wait
for another connection.  The solution?  fork() off another
process.  If it returns 0, you're in the child process, so do
the work.  If you get a positive number, you're the parent,
so go back to listening.

On that thread (pardon the pun), you could have a program that
is interacting with the user.  Rather than making the user
wait while some action is performed (like a backup), fork() a
child process to do the work.  If you recall a couple of weeks
ago, we talked about signals.  Well, when the child process
dies (finishes), the parent process is notified with SIGCHLD.

http://www.ertw.com/~sean/newsletter/June+28%2C+2001

The fork() system call isn't only accessible in C, many other
languages let you use it in the same manner, such as PERL.

I'm going to give you one more example that has no useful
application, except to demonstrate where init fits into all
of this.  See if you can answer the question before trying
this out.

"If the parent process dies before the child process, who is
the child's parent?"

Here's fork3.c, which will attempt to answer that:


<div class="highlight"><pre><code class="c"><span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="p">{</span>
	<span class="n">printf</span><span class="p">(</span><span class="s">&quot;My pid is %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">getpid</span><span class="p">());</span>
	<span class="k">if</span> <span class="p">(</span><span class="n">fork</span><span class="p">()</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">)</span> <span class="p">{</span> <span class="cm">/* child */</span>
	<span class="n">printf</span><span class="p">(</span><span class="s">&quot;I am %d, my parent is %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">getpid</span><span class="p">(),</span> <span class="n">getppid</span><span class="p">());</span>
<span class="n">sleep</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span>
	<span class="n">printf</span><span class="p">(</span><span class="s">&quot;I am %d, my parent is %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">getpid</span><span class="p">(),</span> <span class="n">getppid</span><span class="p">());</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>  <span class="cm">/* parent */</span>
<span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
	<span class="n">printf</span><span class="p">(</span><span class="s">&quot;I am the parent %d, but I&#39;m leaving now</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">getpid</span><span class="p">());</span>
	<span class="p">}</span>
<span class="p">}</span>
</code></pre></div>


I'm using the sleep() library call to make each process wait
so that the child can display its parent before and after it
dies.  This example also demonstrates the way that programmers
use fork() to decide who is the child and who is the parent.

$ gcc fork3.c -o fork3
$ ./fork3
My pid is 3353
I am 3354, my parent is 3353
I am the parent 3353, but I'm leaving now
I am 3354, my parent is 1

The child, 3354, was picked up by PID 1 -- our friend init.

So that's process creation in a nutshell.  Even if you never
use it, understanding fork() is almost essential in order
to understand the rest of the system.  Every time you run a
command, your shell is fork()ing off a new process.  Following
the parent-child relationship in the process tree gives you
a better handle on the state of the system.  This whole
business of parents dying before their children is what
causes zombies (and was going to be today's topic, but I got
sidetracked).

I've posted a poll on the Linux news board, please give your
opinion on the use of C code and the discussion of system
calls in general:

http://boards.brainbuzz.com/boards/vbm.asp?rpg=1&wpg=1&sb=0&pvmlse
&m21050


Long live the Penguin,

Sean
mailto:swalberg@brainbuzz.com

Visit the Linux News Board at
http://boards.brainbuzz.com/boards/vbt.asp?b2

-------------------------
2) Linux News
-------------------------

--------------------------------------
Caldera OpenLinux to Require Licencing
--------------------------------------
I can't believe anyone thinks this is a good idea. Users of
Caldera 3.1 OpenLinux Workstation will be required to buy a
licence for each computer they run it on. I'm thinking that
within six months, they'll either reverse this decision or
go bust. How about you?

http://linuxtoday.com/news_story.php3?ltsn 01-06-25-006-20-PS

---------
CerfBoard
---------
Besides a cool name, this device features a 192 MHz StrongARM
1110 with 32 MB of RAM, 16 MB of non-volatile flash memory,
ethernet, and a lot of IO. Not too useful as a general purpose
computer, but this embedded device prototype fits into 0.015
cubic foot!

http://www.linuxdevices.com/articles/AT2683549967.html

------------------------------
Interview with a PHP Developer
------------------------------
PHP (http://www.php.net) is an ultra cool, super powerful,
web development language, along the lines of ASP. Linux.com
interviews one of the developers here, and he offers some
insight into the future of the language, along with the
reasoning behind ActiveState's commercial interest in the
software. ActiveState is the company that ported PERL to WIN32.

http://www.linux.com/develop/newsitem.phtml?sid&aid466

----------------------------------------
Microsoft to Allow Some Rebranding in XP
----------------------------------------
I guess all the antitrust suits must be paying off. In this
MS press release, our favourite monopoly says they'll allow
OEMs to place icons on the desktop, and remove some Start
menu items. My favourite is that they promise to make the end
user parts of IE easily removable, but then again they've
always claimed you could do that.

http://www.microsoft.com/presspass/press/2001/jul01/07-11OEMFlexibi
lityPR.asp


-------------------------
3) Linux Resources
-------------------------

-----------------
HTTP Benchmarking
-----------------
If you're doing any sort of dynamic web pages, system
administrators everywhere will thank you if you take
performance into consideration. Systems administrators might
also want to see how well the latest upgrade improves speed
on the web server. In both cases, you'll want to do some
benchmarking. This HOWTO explains how it should be done so
that you get reliable data.

http://www.xenoclast.org/doc/benchmark/HTTP-benchmarking-HOWTO/

-------------------
Security Manuals
-------------------
The Idea Hamster, besides being a funny name, is the title
of a project that is developing open-sourced manuals for
security-related topics. There is one on how to perform
security tests, how to write secure code, and much more.

http://www.ideahamster.org/

--------
SNMP FAQ
--------
The Simple Network Management Protocol can be used to get
information on systems such as a Linux box or a network switch.
Despite the "Simple" in the title, the whole concept can be a
bit confusing, so this FAQ will help you out. Network and
Systems people alike should be well versed in this protocol
...used properly, it can make your job a lot easier.

http://www.pantherdig.com/snmpfaq/

---------------
PostgreSQL Book
---------------
This online book is all about PostgreSQL, a free relational
database. PGSQL is very powerful, having many more features
than MySQL. This comes at a cost of resources and more skills
to administer it. Luckily, you'll have this book handy to get
you through it.

http://www.ca.postgresql.org/docs/aw_pgsql_book/index.html

-------------------
XPilot Newbie Guide
-------------------
Ever since finding this game, I've been hooked. XPilot is a
multiplayer game where you control a little spaceship, and
fly around a map fighting with other people. There is even a
team play mode, where the object is to get the other team's
treasure back to your own base. The Newbie Guide here will
show you how to control your ship so you don't get blown out
of the skies quite so fast.

http://www.j-a-r-n-o.nl/Xpilot/Newbie/Unix/newbie.shtml

-------------------------
4) App o' the week
-------------------------
TPC stands for "The Phone Company", which is a project
designed to build a worldwide fax over email service. I
didn't even notice that RedHat has the client for this on
the distribution CDs until the other day! If your recipient
is in an area covered by this, you might just save a few
bucks on long distance. If you live in an uncovered area, it
might be worthwhile to set up a node. Not only are you
giving something to the community, but it's a pretty good
way to get into UNIX administration if you're looking for a
project to do.

http://www.tpc.int

-------------------------
(C) 2001 BrainBuzz.com. All Rights Reserved.
-------------------------

-------------------------

         This message is from BrainBuzz.com.

You are currently subscribed to the
   Hottest Linux News and Resources
   as: sean@ertw.com

To un-subscribe from this newsletter by e-mail:
   send a blank email message to:
   mailto:leave-linuxnews-3825955Y@list.cramsession.com

-------------------------------------------------------

To Subscribe to this newsletter by e-mail:
   send a blank email message to:
   mailto:join-linuxnews@list.brainbuzz.com
-------------------------