简体   繁体   中英

Run bash script from another script and exit first script while second is running

First bash script is:

./second #takes too long

I want kill first bash script while second bash script is still running.

Can I do that?

UPDATE

First script run by cronjob!

If the last thing that the first script does is to call the second script, then do this:

exec ./second

which replaces the first script's process with the second.

otherwise

nohup ./second &
disown

For Linux you would use the "kill" command after obtaining the PID of the program you wish to exit-

http://linux.about.com/library/cmd/blcmdl_kill.htm

I don't know how you would get the PID automatically via a script however.

It appears you can also use "pkill" to terminate processes by name-

Ex-

pkill -9 ping

Or killall-

killall firefox

https://www.digitalocean.com/community/tutorials/how-to-use-ps-kill-and-nice-to-manage-processes-in-linux

The answer below applies to BATCH files, not bash. I read the question wrong.

You can close an instance by getting the PID. You can also use this bit of code-

taskkill /f /im "x"

Where "x" is the name of the program you wish to close, as it would appear in the Task Manager.

Explanation of the parameters I gave-

/im ImageName : Specifies the image name of the process to be terminated. Use the wildcard (*) to specify all image names.

/f : Specifies that process(es) be forcefully terminated. This parameter is ignored for remote processes; all remote processes are forcefully terminated.

More info- http://technet.microsoft.com/en-us/library/bb491009.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM