Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char *argv[]){
- cout<<"Parent pid: "<<getpid<<endl;
- int a = fork();
- int b = fork();
- if(a==0)
- {
- cout<<"pid: "<<getpid<<endl;
- system(">rno1.txt");
- ofstream myfile("rno1.txt");
- myfile.open("rno1.txt");
- for(int i=0;i<20;i++){
- int z = rand()%1000000000;
- myfile<<z;
- myfile.close();}
- }
- if(b==0){
- cout<<"pid: "<<getpid<<endl;
- system(">rno2.txt");
- ofstream myfil("rno2.txt");
- myfil.open("rno2.txt");
- for(int i=0;i<20;i++){
- int y = rand()%1000000000;
- myfil<<y;
- myfil.close();
- }
- }
- else if(a>0){
- wait(NULL);
- c = fork();
- if(c==0){
- cout<<"pid: "<<getpid<<endl;
- int counter = 0;
- ifstream f1("rno1.txt");
- ifstream f2("rno2.txt");
- int num[20];
- int num2[20];
- for(int i=0;i<20;i++){
- f1>>num[i];
- f2>>num2[i];
- }
- for(int i=0;i<20;i++){
- for(int j=0;j<20;j++){
- int count = 0;
- if(num[i]==num2[j])
- cout<<num[i];
- count ++;
- }
- }
- if(count==0)
- cout<<"no common number";
- system("rm rn01.txt");
- system("rm rn02.txt");}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement