A question about the PID of a background function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A question about the PID of a background function
# 1  
Old 03-16-2009
Question A question about the PID of a background function

Dear all,

I'm writing a KornShell script that calls inside it a function in background mode

Code:
#!/bin/ksh

function myfunction
{ . . .}

myfunction |&
. . .

How can I capture the PID of the function myfunction that runs in background?

Thanks in advance
Smilie
# 2  
Old 03-16-2009
Code:
#!/bin/ksh

myfunction |&

echo $!

# 3  
Old 03-16-2009
Quote:
Originally Posted by vgersh99
Code:
#!/bin/ksh

myfunction |&

echo $!


Thanks a lot, it works pretty well now

Regards,
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[SOLVED] Using "$!" to get the PID of the Last Ran Background Process

Hello All, I was looking into creating a script that would be used only to start a Daemon and create a lock file... F.Y.I. It's for Nagios' NRPE Daemon Plugin... Anyway when I run the command to start the Daemon (below): /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d And... (14 Replies)
Discussion started by: mrm5102
14 Replies

2. Shell Programming and Scripting

Execute a function in background and then suspend it

Here is some back ground on the script. The script is to poll an arbitrary number of DB's. To do this I am creating a function that takes the file_path to the DB and the min poll interval as arguments. The function will be called for each DB and then ran in the background. The function I was... (6 Replies)
Discussion started by: ryandavison
6 Replies

3. Shell Programming and Scripting

Background process, return code and pid.

Hey all, Okay, this one is tricky and I'm not sure there is a niec way to do it, or indeed anyway to do it. The main issue revolves around timing out a hung ssh. I am doing this by creating a wrapper script for the ssh with the following requirements. My requirements are: Defineable... (5 Replies)
Discussion started by: RECrerar
5 Replies

4. Shell Programming and Scripting

PID from background ssh

Hello. I was wondering if someone can help me out with something. To simplify my life, I have written a tiny script to open an ssh tunnel through another linux host so that I can access the esxi hosts on that network using the client. For this I have to tunnel ports 443, 902, and 903. Here is what... (1 Reply)
Discussion started by: numetheus
1 Replies

5. Shell Programming and Scripting

does the pid of background process show in /proc?

Hi all, I'm reading <advanced bash scripting> and there is a example to kill a background process in a limited time,as shown below: #! /bin/bash #set -n TIMEOUT=$1 count=0 hanging_jobs & { while ((count < TIMEOUT));do eval ' && ((count = TIMEOUT))' ((count++)) sleep 1... (6 Replies)
Discussion started by: homeboy
6 Replies

6. Shell Programming and Scripting

kill PID running in background in for loop

Guys, can you help me in killing the process which is running in back ground under for loop I am not able to find the PID using ps -afx|grep <word in command I entered> (1 Reply)
Discussion started by: mohan_xunil
1 Replies

7. Shell Programming and Scripting

How to find pid of PS which executed by perl system function

hello All, I need to invoke by perl script some program/command and monitor it for 5 minutes . In case it still running for more then 5 min I need to send a signal which will stop it. I implemeted this as shown below by using eval & alarm and I'd like to know if there is a better way to... (1 Reply)
Discussion started by: Alalush
1 Replies

8. Programming

want to run a function in background

consider the given prg. main() { ..... function1(); /* to write into a file or log */ printf(" "); ..... } when the control reaches function1(), it should get executed in the background.At the same time main's printf(" ") statement should also get executed.i.e... (5 Replies)
Discussion started by: bankpro
5 Replies

9. Shell Programming and Scripting

PID of process started in background??

I am having a problem getting the PID of a process I start in the background is a csh. In tcsh and sh it's simple $! give it to you But in csh this just returns Variable syntax From the man page it should work but it doesn't???? Any help. (2 Replies)
Discussion started by: stilllooking
2 Replies

10. UNIX for Dummies Questions & Answers

subshell & background function

Hello all, Can someone explain to me the advantage between using subshell over a function call in scripts? To me these are the same. Am I wrong to think this? (4 Replies)
Discussion started by: larry
4 Replies
Login or Register to Ask a Question