[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] problemer med fork



On Mon, Nov 13, 2000 at 06:13:24PM +0100, Lars Hansen wrote:
> Her er lidt psedukode, som jeg ville lave( har ikke kodet c i lang tid )


Her noget kode der virker (TM) ;)


#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <readline.h>
#include <history.h>

int main()
{

     pid_t pid;
     char *line = NULL;

     for (;;) {

          free (line);
          line = readline("Tell me something: ");

          switch(pid = fork()) {

          case -1: /* Error */
               exit(EXIT_FAILURE);
               break;

          case 0: /* Child */
               /* NOP  */
               close(STDIN_FILENO);

               /* Do stuff ;) */

               sleep(10); /* Debug ;) */
               printf("I am dead: %d\n", getpid());
               exit(EXIT_SUCCESS);
               break;

          default:
               /* NOP  */
               printf("Child process started, pid: %d\n", pid);
               break;
          }
     }

     exit(EXIT_SUCCESS);
}


-- 
	Christoffer


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *