Sponsored Content
Top Forums Shell Programming and Scripting How to put FTP process as a background process/job in perl? Post 302539809 by vanitham on Monday 18th of July 2011 11:54:53 PM
Old 07-19-2011
Quote:
Originally Posted by pludi
Do you want to do any additional processing while the file is being transferred? If not, I don't see why the transfer process should be separated from the main process.

Otherwise, here's a small script on how to use fork:
Code:
#!/usr/bin/perl -w

use strict;
use warnings;

print "Parent script\n";

my $pid = fork();
if ( $pid == 0 ) {
    print "Child script started\n";
    sleep 5;
    print "Child script ending\n";
    exit int( rand(255) );
}
elsif ( $pid > 0 ) {
    print "Parent script, child has PID $pid\n";
    waitpid( $pid, 0 );
    print "Parent script, child exited with status " . ( $? / 256 ) . "\n";
    exit 0;
}
else {
    print "Error when forking: $!\n";
}

Hi,
Thanks for your reply. My sense is that FTP should not be depended on the main process it should be as an background process. Yes there are chances of additional processing while the file is being transferred

Suppose my main program is main.pl and ftp is callftp.pl how do i utilize the above program and put callftp.pl as an background program?

Regards
Vanitha
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

capture the process id when starting a background process

Hello all, How do I start a background process and save the process id to a file on my system. For example %wait 5 & will execute and print the process id. I can't figure out how to get it to a file. I've tried: > filename 0>filename 1>filename. Any assistance is most appreciated. Thanks, Jim... (10 Replies)
Discussion started by: jleavitt
10 Replies

2. Shell Programming and Scripting

killing unix job after the job process completes

Hi, Thanks in advance. i need to kill a unix background running job after that job process completes. i can kill a job by giving the following unix command kill -9 processid how to kill the job after the current process run gets completed ? Appreciate your valuable help. ... (1 Reply)
Discussion started by: dtazv
1 Replies

3. Solaris

killing a unix job after the job process gets completed

Hi, Thanks in advance. i need to kill a unix background running job after that job process completes. i can kill a job by giving the following unix command kill -9 processid how to kill the job after the current process run gets completed ? Appreciate your valuable help. Thanks... (7 Replies)
Discussion started by: dtazv
7 Replies

4. Shell Programming and Scripting

Perl Background Process - Finshed Yet?

I have a perl process I want to run in background in a cgi, but do not want to continue until process finished code looks like this. sub calc(){ do calculations return value } In another Perl program I call above function such as &calc(); I want to continue after process... (4 Replies)
Discussion started by: photon
4 Replies

5. Solaris

background process

Hi When I run ./script.sh & the script runs in bg But when I close the telnet session, the script is killed also. any idea how to keep this script running? thx (4 Replies)
Discussion started by: melanie_pfefer
4 Replies

6. Shell Programming and Scripting

How to process and run a program in the background in perl?

Hi, I have a query about processing and running Perl program at the background. I have HTML file called Userform.html which accepts input from the user. As soon as input is given the contol goes to get.cgi (get.cgi does some processing and computing tasks). Actually get .cgi takes more... (0 Replies)
Discussion started by: vanitham
0 Replies

7. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

8. Shell Programming and Scripting

How can put a background process to the foreground

Hi, guys: I am working on my own shell using c. When I put a process into the background, how can I put it back to the foreground using tcsetpgrp? Thanks (3 Replies)
Discussion started by: tomlee
3 Replies

9. Shell Programming and Scripting

How to call a background process in perl?

Hi, I want to put the following code as a parallel or background process The program is as below: $n=10; #Count of files to be created. for($j=0;$j<=$n;$j++) { open(FH,">files_$j.txt") || warn "cannot create a file\n"; { print FH "count of file: $j\n"; #Sample data to be written. just... (5 Replies)
Discussion started by: vanitham
5 Replies

10. Shell Programming and Scripting

Make background process interact with fg process

Hi, I have written a menu driven shell script in which as per the choice, I run the another script on background. For eg: 1. get info 2)process info 3)modify info All the operations have different scripts which i schedule in background using &. However I wish to display the error... (0 Replies)
Discussion started by: ashima jain
0 Replies
bind_to_cpu(3)						     Library Functions Manual						    bind_to_cpu(3)

NAME
bind_to_cpu - Bind execution to a specific CPU. LIBRARY
Mach Library (libmach.a) SYNOPSIS
#include <sys/types.h> #include <sys/resource.h> int bind_to_cpu( pid_t pid, unsigned long cpu_mask , unsigned long flag ); PARAMETERS
Specifies the target pid. You must have access rights to the pid. Specifies the CPU on which the thread should run. The target CPU is the bit index in the mask. If you set more than one bit, an error is generated. A cpu_mask of zero clears any previously set CPU binding. Specifies options to CPU binding. Currently only the option BIND_NO_INHERIT is supported. When set, this option causes child processes and threads to not inherit the CPU binding. DESCRIPTION
Upon return from bind_to_cpu, all threads of the target pid are running on the target CPU. Bound threads are not eligible for execution on any other CPU. You release CPU binding by invoking bind_to_cpu with a cpu_mask of zero. EXAMPLES
/* * Fork child process and force it to run on cpu number 3. * Processes created by the forked child will not inherit bindings. */ #include <sys/resource.h> #include <sys/sysinfo.h> #include <sys/signal.h> #include <sys/types.h> #define CPU_3 0x8 /* Bit 3 set */ main() { pid_t pid; if (pid = fork()) { /* parent */ if (bind_to_cpu(pid, CPU_3, BIND_NO_INHERIT)) { kill(pid, SIGKILL); exit(1); /* bind_to_cpu() will print error msg */ } sleep(2); /* wait for child to print CPU */ } else { /* child */ long cpu_num; sleep(1); /* wait for parent to bind CPU */ getsysinfo(GSI_CURRENT_CPU, &cpu_num, 0L, 0L, 0L); printf("child running on CPU %d ", cpu_num); } } In this example, the CPU_3 symbol is defined so that bit three in the bit mask is set. When the pid returned from the fork routine identi- fies the parent routine, the bind_to_cpu routine is called. This routine binds the child process to CPU number three, as specified in the CPU_3 symbol. When the pid returned from the fork routine identifies the child routine, the child routine sleeps to give the parent routine time to set its CPU binding. Then it uses the getsysinfo call to determine its CPU and displays its CPU with the printf routine. If the return value from the bind_to_cpu routine indicates an error, the parent process kills the child process and exits with an error status. RETURN VALUES
Upon successful completion, bind_to_cpu returns zero. Upon error, a -1 is returned. RELATED INFORMATION
Commands: runon(1) Functions: getsysinfo(2) delim off bind_to_cpu(3)
All times are GMT -4. The time now is 10:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy