LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   linux prompt break and start (https://www.linuxquestions.org/questions/linux-newbie-8/linux-prompt-break-and-start-4175478082/)

123raajesh 09-22-2013 03:43 AM

linux prompt break and start
 
colucix,

I have a doubt is it possible to execute a series of commands with prompt.
Say

Start
Command1
Command2

stop (to verify)

Start (should not restart from 1st command)

Command3

stop (to verify)

start (should not restart from 1st or 3rd command)

Command4

end

Please suggest, thanks in advance.

colucix 09-22-2013 06:04 AM

You can simply stop the process by pressing Ctrl-Z, which is equal to send a TSTP signal (see man 7 signal for details). The process will be in a idle state until it receives a CONT signal. Since the process is sent in background upon interrupting, you can restore it by means of the fg command. Is this what you're looking for?

123raajesh 09-22-2013 06:35 AM

linux prompt break and start reply
 
Quote:

Originally Posted by colucix (Post 5032463)
You can simply stop the process by pressing Ctrl-Z, which is equal to send a TSTP signal (see man 7 signal for details). The process will be in a idle state until it receives a CONT signal. Since the process is sent in background upon interrupting, you can restore it by means of the fg command. Is this what you're looking for?

Hi, idea same but these commands are executed through a file, there is a prompt asking user to proceed(Enter) or stop (CTRL+c). If i do this the script will end here itself say after Command2, as per my example. But, want the user to give chance to review the executed results and then user should be able to proceed from Command3, that is user has breaked at command2 and start at Command3.

Sorry if i am confusing.

Thanks

colucix 09-24-2013 03:24 AM

If I understand well you want to give the ability to the user to interrupt a running process and proceed with the following statements in the script, is it correct?

In this case, if you want to use Ctrl-C to interrupt a single process, you have to use trap to execute a different action, otherwise the whole script will be interrupted. Then you launch the interruptible command in background and use wait to pause the script until the process has terminated OR until the user presses Ctrl-C to stop it. Example:
Code:

#!/bin/bash
#
function control_c () {
  kill -9 $pid
}

trap control_c SIGINT

command_one
command_two &
pid=$!

echo "Press Ctrl-C to stop the execution of current process..." && wait $pid

command_three &
pid=$!

echo "Press Ctrl-C to stop the execution of current process..." && wait $pid

Hope this helps.


All times are GMT -5. The time now is 11:06 PM.