Visit Our UNIX and Linux User Community

capture the process id when starting a background process

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting capture the process id when starting a background process
# 8  
Old 03-29-2002
In ksh, $! gives the process ID of the last background command invoked ($PPID is the parent PID).
somecommand &
echo $! >

# 9  
Old 03-31-2002
To save the PID of to pid
Code: & echo $! > pid

This should work in sh, ksh and bash, but not csh.
# 10  
Old 04-01-2002
Thanks Jimbo, moderator, that did it. Very much appreciated, thank you all for your responses.
Jim Leavitt
# 11  
Old 04-04-2002

$? gives the PID of the last process.

But if many processes start consequently,I'm not sure that we
can get the one we search.

Previous Thread | Next Thread
Test Your Knowledge in Computers #630
Difficulty: Medium
According to Lifewire, as of November 1, 2018, a total of more than 3.2 billion iPhones had been sold.
True or False?

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

How to put FTP process as a background process/job in perl?

Hi, I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming. So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Discussion started by: vanitham
5 Replies

3. Shell Programming and Scripting

Log Capture for Background Process

Hi , I am running a backgorund process called ./hello & Now i need to capture the log file as it produces the output . i am not able to use " >> " nor " tee " to capture the output file / log file . Please let me know how can i do it ? Regards, Deepak Konnur (3 Replies)
Discussion started by: dskonnur
3 Replies

4. 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

5. Shell Programming and Scripting

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

6. Shell Programming and Scripting

facing problem in starting a process in background using shell script.

hey all, i am working on sun solaris machine and i want to start a process in background using shell script (actually i wanna start tomcat server using shell script). please dont tell me that append a & at last because this is not working in the shell script. i have also used nohup and... (8 Replies)
Discussion started by: dtomar
8 Replies

7. Shell Programming and Scripting

Help in background process

Hi, I have a main script(main.ksh) within which I have called another script(sub.ksh). The sub.ksh script is made to run in the background using '&'. The main.ksh script logs the information in a logfile main_ddmmyy and the sub.ksh script also logs the information in the log file sub_ddmmyy.... (5 Replies)
Discussion started by: chella
5 Replies

8. Solaris

how to capture oracle export log while running as background process

I ran the Oracle 9i export command from a terminal to export out a big table using "exp andrew/password file=andrew.dmp log=andrew.log" From the terminal I can see that the export is running as there is some output from the oracle export job. The export job is not complete yet. When i go check... (4 Replies)
Discussion started by: hippo2020
4 Replies

9. Shell Programming and Scripting

process in background

Hi Guys, I am facing some weird problem with my shell script. The script shows up a menu and for every ontion internally calls a shell script which start/stop various servers. When I am using '&' while calling the internal shell script so that the server run in the background. For exiting... (1 Reply)
Discussion started by: agoyal
1 Replies

10. Shell Programming and Scripting

cause a process to be in background

Hi My script -, execute in background and in foreground . holds the process ID of program2. after a while needs to move the process of to background. How? (0 Replies)
Discussion started by: avnerht
0 Replies

Featured Tech Videos