process handling

Posted on 2002-05-09
Last Modified: 2010-03-05
I have a perl cgi script which executes a program using `` what I would like to do, is start the process and then immediatly send the response back to the user, without waiting for the process to finish.

In other words: the user makes an http request, the script starts a process, sends back the response, and some time later the process finishes (without anyone really knowing about it).

How can I do this?

Question by:_D_
  • 3
  • 2

Expert Comment

ID: 6999091
You could merely append an ampersand (&) to the end of the system call:

  `/some/process arg1 arg2 &`;


Accepted Solution

jhurst earned 200 total points
ID: 7000311
This is exactly what fork() is for.

$x=fork();  #make two copies of the running process
if ($x > 0) { #the maker of the copy gets the
              #pid of the new one
  print ...   #whatever you want to tell the user
  close(STDOUT); #ensure that the web server knows
  }           #we are done
else {
  #we are the second copy
  ... do whatever he wants to do, no one will know


Expert Comment

ID: 7001970
In the case where the other process is as described by japhyrpi I somewhat agree that the & method works, if the OS is one that supports the & method.  

The things I do not like about this is that: 1) it does not take advantage of multi-threading where implemented, 2) it is OS specific, 3) it does not allow the rest of the work to be done in the same perl script.

But, I do agree it will work with these restrictions.

Expert Comment

ID: 7002022
jhurst - well, fork() is OS dependent too.  ActivePerl has only recently provided support for it.

Expert Comment

ID: 7002302
correct.  However, fork() is defined in perl, the & is not.  Also, most decent multi-tasking operating systems implement fork() therefore it makes its way into perl there too.  Now, MS products are of course a different issue.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Validating the data using Oracle DBD module. 5 65
Expect & sshpass package for Solaris 10 x86 15 896
Port 80 requests 16 87
Add additional column to .csv using Perl. 8 128
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now