Executing a few commands in bash once an executable closes? [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I have an application that will shut itself down at a specific time, is there a way for a bash script to execute some commands (like move log files, clean temp files) after the application has closed then restart it?

It's possible to reinvent this wheel, though not at all a good idea.
This can be as simple as:
while :; do
./run-your-process
do-some-cleanup
done
But really -- don't. Use runit, upstart, daemontools, systemd, supervisord, or one of the many, many other tools which will automate this process for you.

If you start the main process in your script in the background, you could turn on job control in bash with 'set -bm' and then trap SIGCHLD and do your cleanup and restart in the signal handler.
#!/bin/bash
set -bm
childexit() {
... cleanup and restart
}
trap 'childexit' SIGCHLD
mainprocess &

Related

Alt-Tab for Linux command line? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I am wondering if such a thing exists to where I could run a Java program remotely through SSH on my VPS and then Alt + Tab so that I can run other things in the command line without having to reconnect in a separate tab. I've tried looking through the Java options in the manual, but I couldn't find anything insightful.
In Linux/Unix kind system there is a utility called nohup. You can invoke any command or process using nohup; it will make your terminal free after execution. Linux/Unix systems also support background jobs by appending the character & at end of your command.
So if your Java process is as follows,
java <your program>
you can run it as follows:
nohup java <your program> &
This modified command frees your terminal and you can run another command as per your need.

How to stop a c++ code from running [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
I clicked on a.out of a code in Linux, now I want to stop running code but as I didn't use the terminal, I don't know that how can I stop the code from running. What can I do?
I am running another code from last week.
I can not kill both by turn off the computer because the first code is running from previous week and I don't have time to run it again
So, if you're running two instances of a.out (which I'm just assuming because your question is unclear...) then, as other users have said, run:
pgrep a.out
If the second a.out process is the one you want to kill, take the larger PID number (in your case it seems to be 19564) and run:
kill 19564

how to trace a shell script running the background? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I have run a script like this:
script.sh > terminal.txt 2>&1 &
It contains long loops.
how can I trace (which process with what name and what id was created) that script and kill the process to terminate that?
Type fg in the terminal. Then type Ctrl+c.
See: Job Control Commands
Though, #hek2mgl 's answer was great help and paved the way to solution, but the actual solution is a bit different:
Type fg in the terminal.
Then type Ctrl+z.

What is the easiest way to create a script that runs on the next reboot only? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am looking to create a script that executes on the next reboot only (not each reboot).
For example, I have script test.sh:
cd /tmp
touch toto.txt
What is the easiest way to execute this script only on the next reboot?
By easiest I mean : minimal number of commands, and independent of the linux OS/Version (if possible).
After several searches I found I can use the init.d system. But I think that's not the best way, because my script must run only once.
Add something like
LOCKFILE=/var/lock/test_sh_done
if [ ! -f ${LOCKFILE} ]; then
touch ${LOCKFILE}
/path/to/test.sh
fi
to /etc/rc.local, and make sure that /etc/rc.local has the execute bit set. If you want to run it again at the next reboot, just delete the LOCKFILE.

How to kill rsync gently? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I'm running rsync on a large number of files, and I want to kill the process without leaving any partial files. Is there a way to kill the process gently? I've been looking through the manpages for rsync and kill, but I can't determine if SIGSTOP or SIGTERM will allow rsync to finish its current file before terminating.
From the rsync man page:
EXIT VALUES
0 Success
...
20 Received SIGUSR1 or SIGINT
...
so it would seem that either of these signals can be used to stop a transfer.

Resources