Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1.  
  2. int main(int argc, char *argv[]){
  3. cout<<"Parent pid: "<<getpid<<endl;
  4. int a = fork();
  5. int b = fork();
  6. if(a==0)
  7. {
  8. cout<<"pid: "<<getpid<<endl;
  9. system(">rno1.txt");
  10. ofstream myfile("rno1.txt");
  11. myfile.open("rno1.txt");
  12. for(int i=0;i<20;i++){
  13. int z = rand()%1000000000;
  14. myfile<<z;
  15. myfile.close();}
  16. }
  17. if(b==0){
  18. cout<<"pid: "<<getpid<<endl;
  19. system(">rno2.txt");
  20. ofstream myfil("rno2.txt");
  21. myfil.open("rno2.txt");
  22. for(int i=0;i<20;i++){
  23. int y = rand()%1000000000;
  24. myfil<<y;
  25. myfil.close();
  26. }
  27. }
  28.  
  29. else if(a>0){
  30. wait(NULL);
  31. c = fork();
  32. if(c==0){
  33. cout<<"pid: "<<getpid<<endl;
  34. int counter = 0;
  35. ifstream f1("rno1.txt");
  36. ifstream f2("rno2.txt");
  37. int num[20];
  38. int num2[20];
  39. for(int i=0;i<20;i++){
  40. f1>>num[i];
  41. f2>>num2[i];
  42.  
  43. }
  44. for(int i=0;i<20;i++){
  45. for(int j=0;j<20;j++){
  46. int count = 0;
  47. if(num[i]==num2[j])
  48. cout<<num[i];
  49. count ++;
  50. }
  51. }
  52. if(count==0)
  53. cout<<"no common number";
  54. system("rm rn01.txt");
  55. system("rm rn02.txt");}
  56.  
  57.  
  58.  
  59. }
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement