简体   繁体   中英

How can i wait for a program to end and then automatically start a second program in the Linux console?

How can I wait for a program to complete and then start another program automatically in another console?

EDIT: The first program can be long running and the other program should start right after the completion of the first program.

tail -f --pid=xyzu /dev/null && second_program

for example, in one console (terminal) invoke cat . In another console, use pstree -p | grep cat pstree -p | grep cat to find its process id. Then, in that other console, type tail -f --pid=6169 /dev/null && ls (replace the number with the correct one and use the needed command instead of ls ). Then, end cat with CTL-C .

EDIT: Another example is, you want to shutdown the computer automatically when a long running program has completed:

first, find the pid of the long running program:

pstree -p | grep long_running_program pstree -p | grep long_running_program For instance, you find the pid 3373 . Now, use the command: sudo tail -f --pid=3373 /dev/null && shutdown -h now

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