#include <iostream>
#include <string>
#include <vector>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <wait.h>
using namespace std;
int main()
{
pid_t pid, pid2;
pid = fork();
if (pid > 0)
{
pid2 = fork();
if (pid2 == 0)
{
// Change "wc" to "sort" and this is working fine on my machine
execvp("wc", NULL);
}
}
else
{
execvp("ls", NULL);
}
wait4(pid, NULL, 0, NULL);
wait4(pid2, NULL, 0, NULL);
}
Last edited on
Just a sleepy-time guess but is it because pid and pid2 are not initialized to 0?
I can't help you much but in my implementation it does not cause any "memory exhausted" error neither does anything either of course.