Forgot to use & after command, need to send process to background - command-line

I have been running a program using nohup but I forgot to add & after the command so the terminal is stuck on the process that has been running for hours. the script I am running in python generates 5 processes each time.
Is there anyway I can make the entire script to continue in the background (get the same effect as an &) without killing and rerunning the process.

Hit Ctrl-Z to suspend the process.
Then bg to tell it to run again as a background process.

Related

Mac Terminal to run a bash script that starts a swift program & restarts every hour

I am looking for some support on creating some way of running a swift command in terminal to run a program and then stop it after 1 hour then restart.
Example of manual process:
Open Termain.
cd my app
swift run my program --with-parameters
ctrl+c (after 1 hours)
Restart with step 3
I am sure there must be some way using a bash script maybe to start the program by command, kill it after 60min and restart it with a continuous loop like that.
Thanks :-)
You can set up a cron job to do this. Basically, you'll have a bash script, say it's located at /Users/ben/scripts/run_my_program.sh that will, at every hour:
Terminate the current running process (kill pid)
Execute the swift run my program --with-parameters and spit out the process ID
you can get the PID of the swift process you launch with echo $!, and then use sleep 1h to sleep for 1 hour and then kill the process with kill -9 and the PID you got in the first step.

How to track the progress of command executed using Start command

Consider an command which has to be executed more than once at the same time, I have created a bat file in which Start command is used to execute the command multiple times at once. But there are couple of problem I am facing,
After starting all the commands the main batch file is closed. It is not waiting until the new command window has done its job.
We are not able to keep track of the progress in new windows, for example consider the commands are executed from team city(CI) then the progress is not tracked.
Please help me on this, Thanks in Advance!
1) - Use START "" /WAIT, than start command wait till started process terminate, than continue running batch file.

Exit from REPL without killing background process

I'm using sys.process inside REPL as kind of shell. There are many uses for scala in a shell. And I invoke some external programs, of course. But I discovered that I could not leave the REPL with a background proccess running. And if I kill the sbt by either Ctrl-C or sending signal, the background process is killed also. I'd like to leave sbt and keep all invoked processes running. How can I do so?
The problem isn't with SBT or Scala but with the child process you created. The child needs to "daemonize" to become independent of the parent process. How to do that depends on what kind of process you are invoking and which OS you are running on. On Linux, using the following script as a wrapper around whatever process you are calling works:
#!/bin/bash
nohup $# 2>&1 >/dev/null &

Jenkins - Close the Jenkins job as soon as one of the parallel scrips fail

I'm running two Perl scripts in parallel in Jenkins
some shell commands
perl script 1 &
perl script 2 &
wait
some more shell commands
If one of the perl scripts fail in the middle of the execution , the job waits until the other script runs (as it is executed in parallel in background).
I want the job to stop as soon as one of the script fails and not waste time by completing the execution of other script.
Please help.
You set up a signal handler for SIGCHLD, which is a signal that is always delivered to the parent process when a child exits. I'm not aware of a mechanism to see which child process exited, but you can save the subprocess process identifiers and just kill both of them when you receive SIGCHLD:
some shell commands
perl script 1 &
pid1=$!
perl script 2 &
pid2=$!
trap "kill $pid1 $pid2" CHLD
wait
some more shell commands
The script above has the downside that it will kill the other script regardless of the exit status of the subprocess. You could in the trap, if you want to, add a check for the exit status. The subprocess could e.g. create some temp file if it succeeds and the trap could check if the file exists.
Typically with Jenkins you would have the parallel steps running as separate jobs (or projects as they are sometimes known) rather than steps in a job. This would then allow the steps to run in parallel across different slave machines and it would keep the output for the jobs in a separate place.
You would then have a controlling job running the other parts.
I like the Multijob plugin for this sort of thing.
There are alternatives which may suit better, such as Build Flow Plugin which uses a DSL to describe the jobs you want to run

Returning handle to calling script perl

I have an executable which can run perl scripts using the following command at the prompt:
blah.exe Launch.pl
The way we have our tests setup is that we call the Launch.pl from Parent.pl like this "blah.exe Launch.pl" - script within script. However, when executing the command with backticks/system command the parent .pl script execution waits till I get the handle back by closing and exiting out of the application (blah.exe). At this point the code in parent.pl continues to execute.
How do I return the handle back to the parent .pl script after I get done running the code that is contained in the Launch.pl
So, parent.pl calls "blah.exe Launch.pl"; but after running the code inside Launch.pl inside the application (blah.exe) it just sits there waiting to be exited out of so that the code in parent.pl can continue running. I need to keep the application (blah.exe) open till I am done running a bunch of scripts one after another.
Run blah.exe in the background. When you are done with the Parent.pl, terminate the application with kill.