Linux is a simple fork

The 1 to show two sub function
//add.c
#include<stdio.h>
int main()
{
    int a=3,b=2;
    printf(a+b=%d\n",a+b);

    return 0;
}

//minus.c
#include<stdio.h>
int main()
{
    int a=3,b=2;
    printf(a+b=%d\n",a+b);

    return 0;
}


//The main function of the
#include<stdio.h>
#include<unistd.h>
int main()
{
    
	int pid = fork();
    
	if(pid <0 )
    
	{
	
		printf("make process error!");
        
		return 0;
    
	}
    
	if(pid == 0 )
    
	{
        
		printf("child process running , minus sucessed!");
        
		execl("minus",NULL); //Output a-b=1;   
	}
    
	else
    
	{
	
		printf("father process running , add  sucessed!\n");
	
		execl("add",NULL);//Output a+b=5;
	}
    

	return 0;

}


//The results are
father process running , add sucessed!
a+b=5;
a-b=1;


All the great predecessors ah, child process running, minus successed! Where this sentence to.?

Started by Bowen at November 17, 2016 - 9:03 AM

//Modified minus function
//minus.c
#include<stdio.h>
int main()
{
    int a=3,b=2;
    printf(a-b=%d\n",a-b);

    return 0;
}

Posted by Bowen at November 30, 2016 - 9:54 AM

printf("child process running , minus sucessed!");
Instead of
printf("child process running , minus sucessed!\n");
Try it

Posted by Gwendolyn at December 11, 2016 - 10:47 AM

Output buffer the child process blocked! Do not flush the output buffer!
Add "\n" or fflush (stdout) can!

Ps: addition and subtraction procedure printf function is missing a left double quotation marks!

Posted by Colin at December 18, 2016 - 11:03 AM

/*The sub function correction*/
//add.c
#include<stdio.h> 
int main() 
{     
        int a=3,b=2;     
        printf("a+b=%d\n",a+b);       
        return 0; 
}
//minus.c
#include<stdio.h> 
int main() 
{     
         int a=3,b=2;     
         printf("a-b=%d\n",a-b);       
         return 0; 
}

Posted by Bowen at December 24, 2016 - 11:24 AM

++

Posted by Caroline at January 08, 2017 - 11:35 AM

There are no bull.?

Posted by Bowen at January 12, 2017 - 11:50 AM