Create log for finished processes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create log for finished processes
# 1  
Old 02-02-2011
Create log for finished processes

Hi, I'm doing a script that generate some background process like

Code:
for file in `find $dir -type f -maxdepth 1 -mtime -1`;
do
    exp="java -cp process.jar testing $file &"
    eval $exp
    echo $! #Get the PID
    echo $(basename $file) >> log
done

Is there a way to know when those generated process are finished? As you can see at this point in the log file the file names are stored, but when the process is started. I want to store the file names when they're finished. Any hint? Maybe a little perl or something?

Thank you
# 2  
Old 02-02-2011
Store the background process pid into a variable and check if the process still exists through the ps -p $BG_PID command in a while loop> And loop through it until the process exists. This is one of the approach you could try..
Code:
BG_PID=$!
while [ ... ]
do
        ps -p $BG_PID 
done
echo $(basename $file) >> log

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Wait until firefox has finished

I am running a macro script from the command line. But the script doesn't wait until the task has finished. firefox imacros://run/?m=macro_script.iim firefox imacros://run/?m=macro_script2.iim How do I get it to wait until the macro has been completed? I am using imacros, a firefox... (1 Reply)
Discussion started by: locoroco
1 Replies

2. Homework & Coursework Questions

create a program that runs two processes linked oven

I need help program in C... :create a program that runs two processes linked oven (1 Reply)
Discussion started by: gizmo16
1 Replies

3. Shell Programming and Scripting

Processes create/join

I'm working with some code in php that creates a process and I want the main program to wait till that process is done running then come back and join. <code> $pid = pcntl_fork(); if ($pid == -1){ die('could not fork'); } else if ($pid){ pcntl_wait($status); } else{ echo... (1 Reply)
Discussion started by: airon23bball
1 Replies

4. Shell Programming and Scripting

How do I know all processes are finished?

Hi all, I am writing a C shell script that starts a program. The program forks of several child processes. Only when all child processes are done, I want to archive my log files. Below is what I have so far, but unfortunately it doesn't work. MyProgram if (-e processes.txt) then rm... (2 Replies)
Discussion started by: Carla
2 Replies

5. Shell Programming and Scripting

How to know a executable has finished his task

Hi frnds, I want to know is there a way by which we can know that a C++ executable has finished its job in shell script. My task is as follows: 1.Shell script calls a executable 2.Executable executes and performs its job of generating some reports. Now i want my shell script to... (4 Replies)
Discussion started by: electroon
4 Replies

6. Programming

programatic ways to create background processes in C/C++

How can we create a background process programmatically? One way I know of is to fork() and exit from the parent process, leaving the child running. It will run as a background process. I would like to know if there are any other ways. In perticular how are daemon processes created? (1 Reply)
Discussion started by: ipzig
1 Replies

7. UNIX for Advanced & Expert Users

how i write script to create 30 processes

helo i make one process for com port . in that i create two thread one for reading data and another for writing data to com port. now i want to write a script which create 30 processes for handling 30 com port. is it good solution for handling 30 com port. Thx & Regards, Amit (2 Replies)
Discussion started by: amitpansuria
2 Replies

8. Shell Programming and Scripting

** Finished ** Syncid.rc

So, the script I've been working on, since I was starting to learn Shell scripting is now complete. This was coded in ksh, and I am very proud of it. What this script does, is syncs up uid's across the network. So if you have 10 servers, with 10 usernames with different UID's - this will... (1 Reply)
Discussion started by: syndex
1 Replies

9. UNIX for Dummies Questions & Answers

Has my script finished?

Hi I'm writing a script which will be run by cron every X minutes. I don't want cron to run my script again if the previous one has not yet finished. When the script first runs, I had the idea to store the Process ID in a file. When cron tries to run the script again, I would check the... (5 Replies)
Discussion started by: Bab00shka
5 Replies

10. UNIX for Advanced & Expert Users

Finding Out When A Process Has Finished?

Problem I have an application which basically runs lots of UNIX programs remotely, using the Telnet protocol. For each program it remotely executes, it stores the process ID (PID) for that process. At regular intervals, I would like my application to take the PID for every process still... (5 Replies)
Discussion started by: 1cuervo
5 Replies
Login or Register to Ask a Question