This question already has answers here:
How to abort execution in GHCI?
(3 answers)
Closed 9 months ago.
I found that when I execute
a = 1:a
a
in command line, I can press Ctrl+c to stop the infinite process.
But Ctrl+c fails to stop the process when I execute
length a
However, Ctrl+c works well when I execute
length [0..]
Why does Ctrl+c sometimes fail to stop the process? Is there any ways to stop the process when Ctrl+c is invalid?
Under Windows, there is a bug where, after pressing Ctrl + C, GHCI appears to exit but still seems to run in the background. The only documentation I could find is https://gitlab.haskell.org/ghc/ghc/-/issues/14150 but I've experienced it myself multiple times using version 9.2.1.when working with infinite data structures like infinite lists [1..].
Related
This question already has answers here:
Command line command to auto-kill a command after a certain amount of time
(15 answers)
Closed 3 years ago.
I am trying to run a script which takes input from text file and based on the number of entries in it, a command is executed as many number of times.
Below is an overview:
cat /tmp/file.txt | while read name
do
<<execute a command using value of $name>>
done
What is happening is sometimes the command executed for particular $name is getting hung due to known issues. Therefore I need in such cases that the command on every value of $name runs only for X number of seconds and if it is not able to complete within that stipulated time, terminate the process and increment loop counter.
I was able to make use of sleep and kill but it is terminated the entire loop. I want the next values to be processed in case command gets hung on a row/value.
Please advise.
Sounds like you might want something like timeout.
timeout 4 <command>
This question already has answers here:
How to kill a child process after a given timeout in Bash?
(9 answers)
simple timeout on I/O for command for linux
(3 answers)
Closed 5 years ago.
Here's my situation: I've made a script in a while loop, but sometimes (say after 20-30 loops) it stops unexpectedly.
I tried to debug it but I couldn't.
I noticed that it stops while executing a command, and it just doesn't do anything when it stops. Now I was thinking: is there a way to tell to another script when the first script stops and it doesn't execute any command in, say 120 seconds? Maybe by constantly observing the output of the first script and when it's giving no output, the second script kills the first one and makes it start again? Sorry for my bad English hope I was clear.
I have two commands, one is logging things in the background and won't stop until I kill it and the second one will eventually stop.
Let's mark them A and B respectively.
I want to execute:
A and B in parallel
Wait for B to finish
Kill A
[do some more stuff]
and repeat that in a loop.
I'm running on MacOS and can't update to Bash 4.x because of GPLv3.
Preferably A (the logger) would start first but I wouldn't mind if it's undefined or B would start first since the difference in time is negligible.
Help would be appreciated.
Thanks
This question already has answers here:
Multithreading in Bash [duplicate]
(3 answers)
Closed 9 years ago.
I am basically trying to write a bash script that suspends some virtual machines running on a host. However, if I write the script sequentially, VMs will be suspended one at a time. Suspending a VM takes some time to save state. How can I let my script suspend the VMs concurrently. In other words, how can I run commands concurrently in a bash script instead of sequentially?
You can background the tasks.
some bash command with options and stuff then with a &
Adding the & will send the command to the background and begin the next.
Put a & after the command for suspending the the VM.
For example if
cmd_to_suspend_vm
was your command to run. You would run
cmd_to_suspend_vm &
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
The following bash command will spawn processes to kernel death. Can you explain the syntax?
:(){ :|:& };:
running this fork() unlimited .. Can one please explain this bash script ?
You define a function called :. Inside this function you call this function twice (:|:) and then you send that process to the background (&). Then you finally call it at the end.
Because of the recursive nature, you'll keep forking. Since there is no base case, the recursion will never end.