LinuxQuestions.org
Visit Jeremy's Blog.
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 08-07-2014, 10:33 AM   #1
kingwang98
LQ Newbie
 
Registered: Aug 2014
Posts: 7

Rep: Reputation: Disabled
Exclamation xterm -e "ping localhost" does not support Ctrl-Z , howto?


The command will get a xterm window and run ping, but
Ctrl-Z did not work, but Ctrl-C,S,Q are working fine.

How to make Ctrl-Z working?
 
Old 08-07-2014, 10:48 AM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Can you copy and paste what goes on on your terminal when you type ^Z. On my terminal it looks like this:
Code:
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.022 ms
^Z
[2]+  Stopped                 ping localhost
jdk

Last edited by jdkaye; 08-07-2014 at 10:50 AM.
 
Old 08-07-2014, 11:02 AM   #3
kingwang98
LQ Newbie
 
Registered: Aug 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
It did not show as yours, did you run xterm -e "ping localhost"
or directly ping localhost ?

It showed ^Z characters but nothing happened.


Linux version and xterm version:


Linux 2.6.32.45-0.3-xen #1 SMP 2011-08-22 10:12:58 +0200 x86_64 x86_64 x86_64 GNU/Linux

/usr/bin/xterm

X.Org 6.8.99.903(238)


Ctrl-C is working fine!!

PLEASE refer to the screen shot below

Click image for larger version

Name:	xterm.png
Views:	13
Size:	36.1 KB
ID:	16069

Last edited by kingwang98; 08-07-2014 at 11:16 AM.
 
Old 08-08-2014, 12:44 AM   #4
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Quote:
Originally Posted by kingwang98 View Post
It did not show as yours, did you run xterm -e "ping localhost"
or directly ping localhost ?
I ran this command from a terminal:
Code:
~$ ping localhost
I guess this is what your mean by "directly ping localhost".
jdk
 
Old 08-08-2014, 01:36 AM   #5
kingwang98
LQ Newbie
 
Registered: Aug 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
But my problem was xterm -e
I must run it like that in my script. I need to start a xterm first and run script or command.

Last edited by kingwang98; 08-08-2014 at 01:40 AM.
 
Old 08-08-2014, 03:21 AM   #6
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Why are you using quotation marks ("") in your command?
Code:
 xterm -e "ping localhost"
and how did you run this command? in another terminal?
jdk
 
Old 08-08-2014, 03:32 AM   #7
kingwang98
LQ Newbie
 
Registered: Aug 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Ok, I have a java process need to call and pop up xterm, the only way I can is by using runCommand(aStringCmd),
so I must run > xterm -e "ping localhost" , without "" it will not work.
You may try the xterm -e "cmd" on your linux and compare to run in the login shell directly: $ping localhost
Ctrl-Z will work on login shell but not with xterm -e "ping localhost"
 
Old 08-08-2014, 04:49 AM   #8
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Q

Quote:
Originally Posted by kingwang98 View Post
Ok, I have a java process need to call and pop up xterm, the only way I can is by using runCommand(aStringCmd),
so I must run > xterm -e "ping localhost" , without "" it will not work.
You may try the xterm -e "cmd" on your linux and compare to run in the login shell directly: $ping localhost
Ctrl-Z will work on login shell but not with xterm -e "ping localhost"
I did try running the command
Code:
xterm -e ping localhost
It worked fine without the quotes. I ran it from a bash terminal and another window with xterm opened up a ran the ping command. ^Z would not work in the xterm since that is the child process. It worked in the parent (bash) process. I guess you would have to put something into your script to get ctrl-z to work.
jdk
 
Old 08-08-2014, 04:54 AM   #9
kingwang98
LQ Newbie
 
Registered: Aug 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
How to make Ctrl-Z work on the child process? I need help to solve that.

Have you tried xterm -e "ping localhost" ? It should also work...
 
Old 08-08-2014, 05:39 AM   #10
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Quote:
Originally Posted by kingwang98 View Post
How to make Ctrl-Z work on the child process? I need help to solve that.

Have you tried xterm -e "ping localhost" ? It should also work...
Yes, I tried it and it works also.
Try searching the web for a solution using How to make Ctrl-Z work on the child process in the search bar. That might turn up a solution.
jdk
 
Old 08-08-2014, 05:43 PM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by kingwang98 View Post
The command will get a xterm window and run ping, but
Ctrl-Z did not work, but Ctrl-C,S,Q are working fine.

How to make Ctrl-Z working?
You can't.

The problem is that there is no bash interpreter running to catch the signal. To get the signal you have to let a shell run - and then issue the ping command to it. NOW the shell can catch the signal. The suspend signal is not enabled until you issue the command...

When you run "xterm -e <application>" you are telling xterm to use <application> for the shell. When that application terminates, so does xterm.

And don't think you can get it enabled by replacing <application> with a shell script. The shell script becomes the application - and has suspend ignored.

If you want xterm to run detached, then put an "&" on the command line (or script) to run it in the background.

I think the "runCommand" function passes the string to bash to interpret, which should allow the xterm to run in background with the "&" included.

Last edited by jpollard; 08-08-2014 at 05:46 PM.
 
Old 08-08-2014, 07:47 PM   #12
kingwang98
LQ Newbie
 
Registered: Aug 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi, The simplest solution is as you said put an "&" at the command, however, my java process will not show the start a login shell that enable me to run Ctrl-Z on it.

So the only way is create a new xterm to send SIGTSTP and SIGCONT with a pid cached from starting the sh script. I need to save pid into a tmpfile and fetch it for further usage.
 
Old 08-08-2014, 09:58 PM   #13
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by kingwang98 View Post
Hi, The simplest solution is as you said put an "&" at the command, however, my java process will not show the start a login shell that enable me to run Ctrl-Z on it.

So the only way is create a new xterm to send SIGTSTP and SIGCONT with a pid cached from starting the sh script. I need to save pid into a tmpfile and fetch it for further usage.
That sounds overly complicated.

What are you trying to do?
 
Old 08-09-2014, 04:18 AM   #14
kingwang98
LQ Newbie
 
Registered: Aug 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
I think so too I need help to find a better and efficient way to support Ctrl-Z

Let me explain:
1. My application is a kind of shell similar to xterm need to start from a Java application
session.runCommand("xterm -e "bash ~/run.sh") and it works fine with Ctrl-C, S Q but not with Ctrl-Z.

2. If I start the shell application directly on the linux login shell $ xterm -e "bash ~/run.sh" &
or $bash ~/run.sh The Ctrl-Z will work on the login shell where it starts.

3.Problem my java process does not have a login shell to run Ctrl-Z and the xterm -e pop up is a child process which does not
support susp signal(however Ctrl-C ,S,Q supported) so if I need to get the same behavior I need to
a)From the java process to detect a Ctrl-Z pressed (separated thread to listen to the key board strike)
b)When key stroked, send kill -TSTP pid and kill -CONT pid to simulate the susp signal behavior.
"echo $$ > pidtmpfile" to get pid of that child process
It is a complicated , overkilled solution...only solution?

4. Lazy solution is do nothing and do not support Ctrl-Z, which make my application less functional.
I can show the user of the child pid, and let user to start another xterm to send signal
at runtime (no java implementation of keyborad listening).. A GUI popup to show the info.

The reason to have a java process is the application is one part of a big Java application that launches it.

Last edited by kingwang98; 08-09-2014 at 04:41 AM.
 
Old 08-09-2014, 08:29 AM   #15
zer0python
Member
 
Registered: Sep 2003
Posts: 104

Rep: Reputation: 20
I'm not a Java programmer, but the C POSIX version of what you want to do should be something like so:

Quote:
/* code */
pid_t p = fork();
if(p < 0) {
/* error.. */
} else if(p == 0) { /* child */
/* children usually inherit signals from parent, no need to
* setup SIGCONT/SIGSTOP since it should already be SIG_DFL,
* which sounds like what you want. However, if xterm/ping
* is doing trickery, you may wish to setup SIGCONT/SIGSTOP
*/
return execl("/usr/bin/xterm", "-e", "ping localhost", NULL);
}

/* parent */
int status;
wait(&status); /* waits for child process to exit; maybe this isn't what you want, i don't know. */
/* ... */
Hope that's helpful or at least insightful
 
  


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
How to set the font-size for "xterm" terminal-emulator (running "bash" shell) ajaygarg Linux - Desktop 1 03-09-2012 01:38 PM
"ping localhost" return a valid IP address, well at least not 127.0.0.1 vbekker Linux - Newbie 21 11-23-2010 11:22 AM
Hardy won't startup, stops with a "fail" and I have to "ctrl+alt+del" to boot. brjoon1021 Ubuntu 10 12-15-2008 07:29 PM
MA-311 on eth0 inaccessible via Linux, "Network Unreachable" error, no localhost ping LGMike Linux - Networking 14 09-22-2003 12:11 AM
Gnome 1.4: howto set ATX-shutdown/restart support in the "logout"-dialog? Debianewb Linux - Software 1 11-08-2002 08:36 AM


All times are GMT -5. The time now is 02:43 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