-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ1.cpp
47 lines (39 loc) · 793 Bytes
/
Q1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <string>
#include <cstring>
using namespace std;
int main(int argc, char* argv[])
{
if (argc > 2 or argc <= 1) //Terminates process if arguments not provided
{
exit(0);
}
else
{
int num = stoi(argv[1]); //Stores argument after converting it into integer
for (int i=0; i<num; i++)
{
char* x = new char;
char* y = new char;
cout<< "Enter the value for x = ";
cin>> *x;
cout<< "Enter the value for y = ";
cin>> *y;
pid_t pid = fork();
if (pid >0)
{
// Parent process
wait(NULL);
}
else if (pid ==0)
{
//Child Process
if (!execl("worker", "worker", x, y,NULL))
cout << "Exec failed" << endl;
}
}
}
}