コード例 #1
0
ファイル: forkex.c プロジェクト: niks2010/osprog
int main(){
	int i=0;
	pid_t pid;
	
	/*if( (pid = fork() ) != 0){
		printf("%d\n\n",pid);
		printf("Error : child process creation unsuccessful\n");
		///_exit(0);
	}*/
	
	pid=fork();
	
	printf("Outside pid : %d\n\n",pid);
	if(pid == 0){
		printf("\n\n\n");
		childProcess();
		//sleep(10000000);
		printf("Exiting from child\n");
		_exit(0);
	}
	
	else{
		printf("\n\n\n");
		parentProcess();
		//sleep(10000000);
		printf("Exiting from parent\n");
		_exit(0);
	}
	
	return 0;
}
コード例 #2
0
ファイル: q1.c プロジェクト: amritsinghbains/UWINDSOR-MAC-2
int main(int argc, char *argv[]){
	int pid;
	

	if((pid=fork()) == 0)
	{	
		childProcess();
	}else{
		parentProcess();
	}
}
コード例 #3
0
static bool
IsSameBinaryAsParentProcess()
{
  mozilla::Maybe<DWORD> parentPid = mozilla::nt::GetParentProcessId();
  if (!parentPid) {
    // If NtQueryInformationProcess failed (in GetParentProcessId()),
    // we should not behave as the launcher process because it will also
    // likely to fail in child processes.
    MOZ_CRASH("NtQueryInformationProcess failed");
  }

  nsAutoHandle parentProcess(::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,
                                           FALSE, parentPid.value()));
  if (!parentProcess.get()) {
    // If OpenProcess failed, the parent process may not be present,
    // may be already terminated, etc. So we will have to behave as the
    // launcher proces in this case.
    return false;
  }

  WCHAR parentExe[MAX_PATH + 1] = {};
  DWORD parentExeLen = mozilla::ArrayLength(parentExe);
  if (!::QueryFullProcessImageNameW(parentProcess.get(), PROCESS_NAME_NATIVE,
                                    parentExe, &parentExeLen)) {
    // If QueryFullProcessImageNameW failed, we should not behave as the
    // launcher process for the same reason as NtQueryInformationProcess.
    MOZ_CRASH("QueryFullProcessImageNameW failed");
  }

  WCHAR ourExe[MAX_PATH + 1] = {};
  DWORD ourExeOk = ::GetModuleFileNameW(nullptr, ourExe,
                                        mozilla::ArrayLength(ourExe));
  if (!ourExeOk || ourExeOk == mozilla::ArrayLength(ourExe)) {
    // If GetModuleFileNameW failed, we should not behave as the launcher
    // process for the same reason as NtQueryInformationProcess.
    MOZ_CRASH("GetModuleFileNameW failed");
  }

  mozilla::Maybe<bool> isSame =
    mozilla::DoPathsPointToIdenticalFile(parentExe, ourExe,
                                         mozilla::eNtPath);
  if (!isSame) {
    // If DoPathsPointToIdenticalFile failed, we should not behave as the
    // launcher process for the same reason as NtQueryInformationProcess.
    MOZ_CRASH("DoPathsPointToIdenticalFile failed");
  }
  return isSame.value();
}
コード例 #4
0
ファイル: main.c プロジェクト: EuV/DistributedLab4
void makeChildren( const int procTotal, const bool isMutex ) {
	for ( int i = 1; i <= procTotal; i++ ) {
		Process process = { procTotal, PARENT_ID, isMutex, 0, 0, 0, 0 };
		TList* list = ( TList* ) malloc( sizeof( TList ) );
		list -> head = NULL;
		list -> tail = NULL;
		process.list = list;

		if ( fork() == 0 ) {
			process.localId = i;
			childProcess( &process );
			break; // To avoid fork() in a child
		} else if ( i == procTotal ) { // The last child has been created
			parentProcess( &process );
		}
	}
}
コード例 #5
0
ファイル: main.c プロジェクト: esussman/Labs
int main(int argc, char ** argv)
{
	
	int pid = fork();
	
	if(pid == 0)
		childProcess(argv);
	else if(pid != -1)
		parentProcess(pid);
	else
	{
		printf("Failure");
	}
		

	return 0;
}
コード例 #6
0
//	MAIN
int main() 
{
	int fd[2];	// 2 file decriptors for two sides (output and input)
	int pid; 	// for getting the status of the child to be forked

	pipe(fd);	//	creating a pipe.

	pid = fork();	//	forking a new child process

	if(pid == -1)
		printf("Error in creating Child!\n");
	else if(pid == 0)
		childProcess(fd);
	else
		parentProcess(fd);

	return 0;
}
コード例 #7
0
ファイル: procode.c プロジェクト: imrojq/College-Assignments
int main()
{
	//allocDealloc();					//The function for allocation and deallocation is there but not used
	srand(time(NULL));
	pid_t pd1,pd2,pd;	
	char choice[10];
	int variable=0,status;
	pd1=fork();							//First child Process
	if (pd1<0)
		printf("Forking process failed\n");
	else if (pd1==0)
		childProcess(1);
		
	pd2=fork();							//Second child Process
	if (pd2<0)
		printf("Forking process failed\n");
	else if (pd2==0)
		childProcess(2);
	parentProcess();
	pd=wait(&status);					//Waits for any of the two child process to finish 
	printf("Parent detects child process %d was done first\n",pd);
	pd=wait(&status);					//Waits for second process to finish
	printf("Parent detects child process %d is done \n",pd);
	printf("Parent exits\n");
	wait_for_time(1);					//Wait for a given time
	printf("Do you want to execute any file yes or no\n");
	scanf("%s",choice);
	if (strcmp(choice,"yes")==0) 
	{
		printf("The program is moving over to executing another binary\n");		//executes another file
		execute();
	}
	else
	{
		printf("That's all");
		exit(0);
	}

	return 0;
}