re:creating child processes

From: Clunixchit (chitlesh_at_gmail-dot-com.no-spam.invalid)
Date: 05/27/05


Date: Fri, 27 May 2005 09:04:14 +0000 (UTC)

Thanks about those tips!!
i made some modifications, but my output is not what i wanted
i need to make 2 childs from the same parent.
i sld i make 2 switch for that?

#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
//using GNU C exit status
#include <stdlib.h>

int main(){
        pid_t one, two;
        char A = 'A';
        char B = 'B';
        int i=0;

        int desc = open ("aba.txt", O_CREAT | O_RDWR , 0700
);
        if ( desc < 0 ) {
                perror ("open");
                exit(-1);
        }
        
        lseek(desc,0,sizeof(char));
        
        one = fork();

        switch ( one ) {
                case 0 : for(i=0;i<5;i++){
                                write(desc,&A,sizeof(char));
                          }
                          // flushing stdio buffers
                          _exit(EXIT_SUCCESS;
                          
                case -1 : perror("fork");
                          exit(EXIT_FAILURE);
                          
                default : waitpid(one,NULL,0);
                          two = fork();
                          if ( two == 0 ) {
                                write(desc,&B,sizeof(char));
                                exit(EXIT_SUCCESS);
                          }
                          waitpid(two,NULL,0);
                          close(desc);
                          system("cat aba.txt");
                          exit(EXIT_SUCCESS);
        }

}



Relevant Pages

  • Re: DataSet vor Update säubern
    ... Im Gegensatz dazu wäre eine "tiefe" Datei etwas in XML Form, ... >> allen seinen auch vielleicht später in der Datei kommenden Childs ... > Bringt denn ein später kommendes Cild keinen Parent mit? ... kommt, wird dafür im Dataset ein neuer Parent angelegt, und der Childteil ...
    (microsoft.public.de.german.entwickler.dotnet.datenbank)
  • Parent-Child Relation und Identity Column
    ... lokale Identity-ID für einen neuen Datensatz im lokalen Dataset. ... die Childs in einem Arbeitsschritt anlegen will? ... Natürlich kann ich den Parent beim Updaten auch auf die ... die "wirkliche" ID des Parents in den Child-Datensätze abzulegen, ...
    (microsoft.public.de.german.entwickler.dotnet.datenbank)
  • DataSet vor Update säubern
    ... Ich lese eine flache Textdatei in ein DataSet, ... Sofort, wenn der Child als ungültig erkannt wurde, den Parent im Dataset ... auftauchende gültige Childs würden ja den Rowstate nicht erben. ... Next by Date: ...
    (microsoft.public.de.german.entwickler.dotnet.datenbank)
  • Re: [why oom_adj does not work] Re: Linux killed Kenny, bastard!
    ... Your Kenny-killer will fail, too. ... Maybe the weight for childs should be ... so killing the parent is the right thing if you ... You can only win by by suspending or killing the factory. ...
    (Linux-Kernel)
  • Re: [why oom_adj does not work] Re: Linux killed Kenny, bastard!
    ... It is not always the case, processes start executing different binaries ... Maybe the weight for childs should be ... so killing the parent is the right thing if you ...
    (Linux-Kernel)