my $fork_pid = fork(); if ($fork_pid == 0) #If its the child process { write_pid(); exit(0); } elsif ($fork_pid) #If its the parent process { wait(); if ($limit_file_size == 1) { checkFilesize(); } untaintInput(); uploadFile(); output(); dump_pid(); } else { die "Couldn't fork."; } sub uploadFile { my $upload_filehandle = $query->upload($form_input_name); #grab handle of temporary file open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!"; #open file for write or report errors binmode UPLOADFILE; #write the file in binary mode while ( <$upload_filehandle>) { print UPLOADFILE; #write actual file from the temporary file } close UPLOADFILE; } sub output { #Output page print $query->header(); print "{success: true, data: 'Your file was uploaded successfully!'}"; } sub write_pid { open(MYID, ">" . $upload_dir . '/' . 'current_upload_pid.txt'); print MYID $$; close(MYID); }