Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

High Performance Computing Assignment

Project: HPC
Path: A1 / lsCommand.h
Views: 171
1
#include <stdlib.h>
2
#include <stdio.h>
3
#include <unistd.h>
4
#include <sys/types.h>
5
#include <sys/wait.h>
6
7
void lsCommand(void)
8
{
9
int i = 0;
10
int j = 0;
11
pid_t pid = fork();
12
13
if(pid == -1)
14
{
15
perror("ERROR!");
16
17
exit(0);
18
}
19
else if(pid == 0)
20
{
21
i = execlp("ls", "ls", (char *)NULL);
22
printf("%d", i);
23
}
24
else
25
{
26
wait(&j);
27
}
28
}
29