LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-01-2011, 05:43 AM   #1
diemons
LQ Newbie
 
Registered: Mar 2011
Posts: 4

Rep: Reputation: 0
Smile Shell command equivalent to (Ctrl+C) to exit from a process ?


Hello folks,

I write a script to read a file which is something like a pipe (or) queue , which shows the running status.In normal case, if i open this file with cat command, i have to use ctrl+c to exit this . What command shall i use to do the same inside a shell script ?

I have tried ^C in my script , but it does not exit the process.

Need some help.

Thanks
 
Old 04-01-2011, 06:10 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Please, can you show us the relevant lines of the code? Usually you can interrupt a process by sending the proper signal by means of the kill command. Run
Code:
kill -l
to see a list of the available signals or look at the signal man page (section 7) for a brief description. Ctrl-C is signal 2: SIGINT.
 
Old 04-01-2011, 07:23 AM   #3
diemons
LQ Newbie
 
Registered: Mar 2011
Posts: 4

Original Poster
Rep: Reputation: 0
Tried the command "kill -l " buddy, but does'nt help.

My code looks as below:
--------------------
#!/bin/sh
cat /proc/file_msgq
kill -l
--------------------

All i need is to redirect the ouput of the file to another file(say log.txt) .When it tried this manually using "cat /proc/file_msgq > log.txt" ,then ctrl+c , log.txt file is created but empty .

Any clues ....
 
Old 04-01-2011, 07:29 AM   #4
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
in stead of

Code:
kill -l
use


Code:
exit
i'm not sure, but it's worth a shot
 
Old 04-01-2011, 07:46 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by diemons View Post
Tried the command "kill -l " buddy, but does'nt help.

My code looks as below:
--------------------
#!/bin/sh
cat /proc/file_msgq
kill -l
--------------------

All i need is to redirect the ouput of the file to another file(say log.txt) .When it tried this manually using "cat /proc/file_msgq > log.txt" ,then ctrl+c , log.txt file is created but empty .

Any clues ....
kill -l is meant to show you the available signals. The actual command you need is something like
Code:
kill -s SIGNAL PID
where signal will be SIGINT and PID is the Process ID of the cat command. You can retrieve it using the ps command. Anyway, can you explain why you need to interrupt the cat command? I haven't got the file /proc/file_msgq on my system, so that I cannot test, but if it is a regular file it should be catted in a glitch and the cat command should terminate. Unless it is a named pipe: in this case cat waits for any stream of data flushing through the pipe.

Please, post the output of the following command:
Code:
file /proc/file_msgq
to see what /proc/file_msgq actually is.

In addition, to get the PID of the process and kill it in one-shot you might try the pkill command:
Code:
pkill -SIGINT -f "cat /proc/file_msgq"
Please, see man pkill for details.

Last edited by colucix; 04-01-2011 at 07:47 AM.
 
Old 04-01-2011, 08:16 AM   #6
anil_cdac
LQ Newbie
 
Registered: Feb 2011
Posts: 11

Rep: Reputation: 0
it's better to use exit 1

Last edited by anil_cdac; 04-01-2011 at 08:18 AM.
 
Old 04-01-2011, 06:24 PM   #7
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 103Reputation: 103
kill -s 2 pid --> same as ctrl c
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] vim:ctrl+v command to select some data.But when I push ctrl+v.It doesn't work.. e3399 Linux - Newbie 20 12-07-2010 07:21 AM
kill process more than 3 hours old from shell command saiyen2002 Programming 7 11-16-2010 05:33 AM
How 2 start a stopped process(CTRL+Z)in command prompt babu198649 Linux - Newbie 4 10-15-2007 03:53 AM
Any way to create bash short cuts (like CTRL+l for clear and Ctrl+D for exit) supersubu123 Linux - General 5 05-30-2007 04:02 AM
ctrl+c & ctrl+v equivalent for Gnome terminal window? halfpower Linux - General 2 11-29-2005 03:57 AM


All times are GMT -5. The time now is 08:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration