#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main( ) {
printf ( "I 'am : %d\n " , ( int ) getpid
( ) ) ;
pid_t pid = fork( ) ;
sleep( 2 ) ;
printf ( "for returend %d \n " , ( int ) pid
) ;
if ( pid < 0 ) { //erorr occurend.
} else if ( pid == 0 ) { //child process
printf ( "I am the child with pid %d\n " , ( int ) getpid
( ) ) ; printf ( "Child process is exiting \n " ) ; }
// parent
printf ( "I'am the parent waiting for the child process to end\n " ) ; wait( NULL) ;
printf ( "Parent process is exiting\n " ) ;
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN5cy90eXBlcy5oPgojaW5jbHVkZSA8c3lzL3dhaXQuaD4KI2luY2x1ZGUgPHVuaXN0ZC5oPgoKCmludCBtYWluKCl7CiAgICAKICAgIHByaW50ZigiSSAnYW0gOiAlZFxuIiwgKGludCkgZ2V0cGlkKCkpOwogICAgICAKICAgIHBpZF90IHBpZCA9IGZvcmsoKTsKICAgIHNsZWVwKDIpOwogICAgCiAgICBwcmludGYoImZvciByZXR1cmVuZCAlZCBcbiIsKGludCkgcGlkKTsKICAgIAogICAgaWYocGlkIDwgMCl7IC8vZXJvcnIgb2NjdXJlbmQuCiAgICAgICAgCiAgICAgICAgcGVycm9yKCJmb3JrIGZhaWxlZCIpOwogICAgICAgIAogICAgfWVsc2UgaWYocGlkID09IDApeyAvL2NoaWxkIHByb2Nlc3MKICAgICAgICAKICAgICAgICBwcmludGYoIkkgYW0gdGhlIGNoaWxkIHdpdGggcGlkICVkXG4iLChpbnQpIGdldHBpZCgpKTsKICAgICAgICAgICAgcHJpbnRmKCJDaGlsZCBwcm9jZXNzIGlzIGV4aXRpbmcgXG4iKTsKICAgICAgICAgICAgZXhpdCgxKTsKICAgIH0KICAgIAogICAgLy8gcGFyZW50CiAgICBwcmludGYoIkknYW0gdGhlIHBhcmVudCB3YWl0aW5nIGZvciB0aGUgY2hpbGQgcHJvY2VzcyB0byBlbmRcbiIpOwogICAgd2FpdChOVUxMKTsKICAgIHByaW50ZigiUGFyZW50IHByb2Nlc3MgaXMgZXhpdGluZ1xuIik7CiAgICAKICAgIHJldHVybiAwOwogICAgCn0=