First time I've seen this approach does this actually signal the running process in any way?
Do you know how portable this zero signal is?
Quote:
Originally Posted by Corona688
kill is faster than ps? I think they're both externals..
The POSIX Standards and the Single UNIX Specifications specify that the function call:
shall not actually send a signal but shall perform normai error checking. So, if the process ID is valid and you have permission to send that process a signal, it will return 0; otherwise, it will return -1 with errno set to ESRCH if the process doesn't exist or EPERM if you don't have permission to send a signal to your child. The standards also require that the kill utility behave as though kill(pid, 0) were called when you invoke the command kill -0 pid. All UNIX Systems do this; I can't speak to whether or not Linux systems' kill utilities and system calls conform to these requirements.
As Chubler_XL said, any shell that handles job control that I've seen has kill as a shell built-in. Even if it doesn't, ps usually needs to do a lot more poking around in kernel memory than kill does; so it should be faster.
This User Gave Thanks to Don Cragun For This Post:
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
Obviously a lot of work and thought has been put into this. As far as I know, the requirements:
can be accomplished through utilities xargs and GNU parallel. Here's an example of a number of script names in a data file that will be "executed". First singly (not in parallel), then at most n=2 at a time. The script that "runs" the script name is run with ksh so that the number of processes can be more easily seen.
producing:
My apologies if I missed the point ... cheers, drl
His original script would have been able to run entire, complex, arbitrary shell statements in parallel. He wasn't testing it with them, but it could. This isn't necessarily a good thing, mind you -- leaves the door open for a lot of unintended problems.
Thank you guys, i've tried to adapt some of your suggestions, /proc/$pid, kill -0 $pid, kill($pid,0) but none of them worked as expected.
The hint with a "single id number" was great, that way i just managed to make it even smaller than the previous example, with full functionality!
Screenshot shows how it returns the number of successfully executed scripts, when passed -c...
Hello,
I am running a bash script to do an rsync back on a computer running MacOS High Sierra. This is the script I am using,
#!/bin/bash
# main backup location, trailing slash included
backup_loc="/Volumes/Archive_Volume/00_macos_backup/"
# generic backup function
function backup {... (12 Replies)
Hi
Could someone offer some help on this problem I've got with running a background process.
As part of a script that does a stop/start/status for a piece of software called SAS, the following extract is from part of the start step.
My issue is that when the script is run, the control... (0 Replies)
Hi, below is my master script wihch inturn runs 2 scripts in background
#master_script.sh
./subscript1.sh &
./subscript2.sh &
executed the master_script.sh from unix command prompt
$ ./master_script.sh
it is executing the subscripts and they are completing fine, however master_script.sh is... (2 Replies)
Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Hi all, i hava a specific backgroud process. I have de PID of this process. At some time, the process finish his job, is there any way to catch the exit code? I use "echo $?" normally for commands.
Thanks! (2 Replies)
Hi All,
I have a scenario where I am executing some child shell scripts in background (using &)through a master parent script.
Is there a way I can capture the exit status of each individual child script after the execution is completed. (2 Replies)
I have the following sample script to run a script the jobs with the same
priority(in this case field3) in parallel; wait for the jobs to finish
and run the next set of jobs in parallel.When all the lines are read
exit the script.
I have the following script which is doing evrything I want... (1 Reply)
In my last job someone gave me the command to put in my .profile that let me know when a job I had running in the background finished. It was a word about 5 char long. I can't remember it! (4 Replies)
I have a sript which is going to trigger other 3 scripts in background simultaneously
for eg:
Main Script:(main.sh)
-----------
sh a.sh &
sh b.sh &
sh c.sh &
How to catch the exit status and store it in a variable for all those three scripts in main script. Is there any other way of... (4 Replies)