/*
 *  Copyright (C) 2004 Aleksandar Colovic
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 */
 
#include <pthread.h>
#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
using namespace std;

void* doWork(void* pArg)
{
  pid_t nChildPID = fork();
  if (0 < nChildPID)
    waitpid(nChildPID, 0, 0);
  else if (0 == nChildPID)
  {
    cout << "I'm forked process: " << getpid() << " from parent: " << getppid() << endl;
    execvp ("mozilla", 0);
    exit(1);
  }
  return 0;
}

int main (int argc, char* const argv[])
{
  cout << "I'm main thread in the parent process: " << getpid() << endl;
  pthread_t hThread;
  pthread_create(&hThread, 0, &doWork, 0);
  pthread_join(hThread, 0);
  return 0;
};
