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
# 1  
Old 03-28-2002
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 Leavitt
# 2  
Old 03-28-2002
Sounds like it "could be homework, but I will help none the less.


ioscan -fnC disk & ps -aef |grep ioscan|grep -v ps | awk '{ print $2 }' > cap.PID

This may capture the PID of the ps command, but it works. Even though it is crude.




Smilie
# 3  
Old 03-28-2002
Quote:
Originally posted by Kelam_Magnus


ioscan -fnC disk & ps -aef |grep ioscan|grep -v ps | awk '{ print $2 }' > cap.PID

This may capture the PID of the ps command, but it works. Even though it is crude.

If you use:

ps -ef | grep "[i]oscan" | awk '{print $2}'


then you will not have to worry about capturing the PID of ps -- a handy side effect of using the square brackets.
# 4  
Old 03-28-2002
Thanks for the help, it's close but it doesnt work. This isn't homework, and I should know how to do this myself. I don't. We've got a socket server we want to start and kill nightly. The only way I can think of is to keep the pid around so I know what to kill at night. Any additional help is most appreciated!
Thanks,
Jim Leavitt
Romac Industries, Inc.Smilie
# 5  
Old 03-28-2002
Can you modify the source to the server? If so just have it write its PID to a file somewhere.
# 6  
Old 03-29-2002
Did you try 2>filename?
Also, how is it started?
Some shells, like bash, will store the value of the previous process ID. In bash, I believe it is $PPID.
I can't remember for sure though... anyone else know?
# 7  
Old 03-29-2002
jleavitt, what shell, OS version?

I think his main problem is that he wants to run this in the background. So, when the process kicks off nothing prints to the screen.

I was trying to capture the PID with ps because 2> won't work because there is nothing to capture. Although the " [1] 12345 " appears on the screen, it is after the process is kicked to the background.

It would be easy to do this except that he is trying to run it in the background.

The only thing I can see is to grep for the PID after you kick off the background process.
Login or Register to Ask a Question

Previous Thread | Next Thread

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.sh ./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 - main.sh, execute program1.sh in background and program2.sh in foreground . program1.sh holds the process ID of program2. program1.sh after a while needs to move the process of program2.sh to background. How? (0 Replies)
Discussion started by: avnerht
0 Replies
Login or Register to Ask a Question