Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to pass "ctrl+c" to terminal 1

Status
Not open for further replies.

ashish061291

Programmer
Jan 30, 2012
11
Hi everyone,

I am executing "blktrace" on my /dev/sda.
In my application i have made a GUI which lets user to choose when he wants to stop "blktrace" execution.

Now how can achieve it ??

Also how can i pass "Ctrl+C" to terminal from a perl script ??


Kindly help..
 
Hi

Using the [tt]kill[/tt] function :
Perl:
[b]kill[/b] SIGINT[teal],[/teal] [navy]$pid_of_blktrace[/navy][teal];[/teal]

[gray]# or[/gray]

[b]kill[/b] [purple]2[/purple][teal],[/teal] [navy]$pid_of_blktrace[/navy][teal];[/teal]
ashish061291 said:
wants to [red]stop[/red] "blktrace" execution.
[gray](...)[/gray]
Also how can i pass "[red]Ctrl+C[/red]" to terminal from a perl script ??
Note that there is contradiction : SIGSTOP, which is used to suspends the process, is not the same with the SIGINT sent by Ctrl-C, which interrupts the process.

Feherke.
 
Thnx a ton :)

But is there any way if I can replace $pid_of_blktrace by the process name ??
 
And as i run again and again its pid changes every time.

I can find the pid by using system("pidof -s blktrace");, but then how can i use this information further to stop blktrace execution.
 
Hi

ashish061291 said:
But is there any way if I can replace $pid_of_blktrace by the process name ??
As far as I know, not with Perl core functionality. There would be some alternatives :
[ul]
[li]There should be no need for that. Supposing blktrace was also started by your Perl script, its PID should be known by it.[/li]
[li]Find out the PID using a module, for example Proc::processTable.[/li]
[li]Find out the PID by reading the /proc/ directory.[/li]
[li]Use external command instead :
Perl:
[b]system[/b] [green][i]'killall SIGINT blktrace'[/i][/green][teal];[/teal]

[gray]# or[/gray]

[b]system[/b] [green][i]'pkill -SIGINT blktrace'[/i][/green][teal];[/teal]
[/li]
[/ul]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top