capture the process id when starting a background process


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
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  
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  
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  
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  
Can you modify the source to the server? If so just have it write its PID to a file somewhere.
# 6  
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  
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 for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #551
Difficulty: Medium
If variable i has the value 10, after x = 5 + (i++); the value of x after this code is 15.
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.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. AIX

Background process

how to check the process running in background? how can i run a process in background? pls explain with commands (1 Reply)
Discussion started by: udtyuvaraj
1 Replies

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

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

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

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

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

10. Shell Programming and Scripting

background process

Hello, This has probably been answered in other forms, however I would like to confirm this statement before I use it in production. Will this syntax work for a background process? echo "nohup server_process1 >/dir1/nohup.server_process1 2>&1 &" | ksh Please advise. Thanks (1 Reply)
Discussion started by: jerardfjay
1 Replies

Featured Tech Videos