On Sat, Jun 11, 2005 at 08:08:52AM +0700, kyanh wrote:
> 
> A`, /me ko^ mong cho+` ca^u tra? lo+`i the^' na`y :(( Bo+?i vi`, /me ddang 
> vie^'t Winefish ( http://winefish.sf.net ) -- chu+o+ng tri`nh ddo^i khi go.i 
> chu+o+ng tri`nh ngoa`i va` ddo^i khi pha?i "KILL" (force) chu+o+ng tri`nh 
> ngoa`i ddo'. Tu'm la.i, Winefish pha?i qua?n ly' ID ca'c chu+o+ng tri`nh con 
> no' go.i. Bi chu+` ba'c no'i nhu+ the^', thi`i /me so+. qua', lo+~ khi na`o 
> gie^'t nha^`m thi` ...
> 
> /me theo do~i ca'ch la`m cu?a nhie^`u program. Tha^'y no' cu~ng ko^ co' ca'ch 
> xu+? ly' na`o dda(.c bie^.t. Du+o+'i dda^y la` ca'ch em la`m....
> 
> A`, co' pha?i du`ng "fork()" se~ gia?i qhuyeest ddu+o+jc mo.i chuye^.n ko^?
> 
> ,----
> |  /* fork():
> | create a child proccess the differs
> | from the parent only in its PID and PPID; 
> | the resouce ultilisation are set to 0 */
> `----
> 
> [code]
> /* Taken from SciTTEGTK.cxx
> kyanh: everything emitted from `running' will be captured [ 2>&1 ]
> */
> static gint xsystem( const gchar *command, const gchar *outfile )
> {
>  gint pid = 0;
>  /* fork():
>  create a child proccess the differs from the parent only in its PID and PPID;
>  the resouce ultilisation are set to 0 */
>  if ( ( pid = fork() ) == 0 ) {
>   close( 0 );
>   gint fh = open( outfile, O_WRONLY );
>   close( 1 );
>   dup( fh );
>   close( 2 );
>   dup( fh );
>   DEBUG_MSG( "xsystem: running now [%s]\n", command );
>   execlp( "/bin/sh", "sh", "-c", command, NULL );
>   exit( 127 );
>  }
>  return pid;
> }
> [/code]
> 
> To+'i gio+`i /me va^~n kho^ng hie^?u gi` he^'t :((

fork() is the only way for a user to create a new process in Unix.

>From "The design of the Unix Operating System", Maurice J. Bach page
193 : "... It (fork() system call) also picks a unique ID number for the new
process, one greater than the most recently assigned ID number. If
another process already has the proposed ID number, the kernel
attempts to assign the next higher ID. When the ID numbers reach a
maximum value, assignment starts from 0 again. Since most processes
execute for a short time, most ID numbers are not in use when ID
assignment wraps around."

Linus used the book as the reference when he first wrote the Linux
kernel so the algorithm in Linux is the same. Apparently, there is no
reason to do differently. But the only way to be sure is to look at
kernel/fork.c.

For your problem, when your child process exit(), it has not gone away
yet. It enters a state called zombie where its pid is kept by kernel
until your parent process calls wait(). I dont know exactly what
happens if you kill a zombie process, so you need to google for it.
But if you dont wait() then you never kill off an innocent process.

Btw, I am now interested in Plan 9 operating system. I wonder if there's
someone here having the same interest. Linux is cool and it will be a
comfortable working system for a while. But it is arguably awkward in
networking and distributed computing where Plan 9 is excellent. So
future may lie in Plan 9. As the matter fact, Linux now is
incorporating lots of ideas from Plan9. However "Unix's problems are
too deep to fix", you knew that if you already knew Plan 9 ;).



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
VietLUG-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vietlug-users

Trả lời cho