-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell_toets.cpp
More file actions
50 lines (42 loc) · 1.37 KB
/
shell_toets.cpp
File metadata and controls
50 lines (42 loc) · 1.37 KB
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
48
49
50
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
using namespace std;
int main(int argc, char **argv)
{
pid_t pid; // integer that can store a process ID (use pid_t for portability)
if ((pid = fork()) == -1) // system functions also set a variable called "errno"
{
perror("fork"); // this function automatically checks "errno"
// and prints the error plus what you give it
return EXIT_FAILURE;
}
// ---- by when you get here there will be two processes
/*
Hy voer eers die parent proses uit en dan kom hy later weer terug vir die ander een.
Dis asof hy in 'n loop is maar ek weet nie wat aangaan nie.
*/
if (pid == 0) // child process
{
cout << "Input parameters:" << endl;
for(int i = 0; i < argc; ++i)
{
//cout << argv[i][0] << endl;
//as dit 'n option is
if(argv[i][0] == '-' && (unsigned)strlen(argv[i]) == 2)
cout << argv[i] << endl;
//as dit 'n argument is
else if(argv[i][0] != '-')
cout << argv[i] << endl;
else
cout << "Don't recognize this character: " << argv[i] << endl;
}
}
else // parent process
{
std::cout << "Doen die parent funksie se goed." << pid << std::endl;
}
return EXIT_SUCCESS;
}