LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-31-2016, 09:43 AM   #1
sub320
Member
 
Registered: Jan 2016
Posts: 116

Rep: Reputation: 3
run script error


I have a script as below

Code:
if [[ ... ]] ; then
top
fi
it works fine , when run it , it run "top" command on the foreground.

Now , I wold like to run the command "top" in background , it changed the script to as below , it pops the error "top: failed tty get" , would advise what is wrong , how to fix it . thanks .

Code:
if [[ ... ]] ; then
top &
fi
 
Old 01-31-2016, 10:48 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well the error message appears to be quite clear on the problem, ie. you are trying to run top without a tty attached.
I guess the real question would be why you would want to run it in the background??

I am also not quite sure on the point of '...' as a test, but as it always seems to be true what is the point of the if at all?
 
Old 01-31-2016, 01:07 PM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
you ought to try xterm -e top & (or choose your favorite terminal emulator)
 
1 members found this post helpful.
Old 01-31-2016, 08:54 PM   #4
sub320
Member
 
Registered: Jan 2016
Posts: 116

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by pan64 View Post
you ought to try xterm -e top & (or choose your favorite terminal emulator)
thanks reply ,

when run it , it pops the below error , would advise how to fix it ?

Code:
Warning: This program is an suid-root program or is being run by the root user.
The full text of the error or warning message cannot be safely formatted
in this environment. You may get a more descriptive message by running the
program as a non-root user or by removing the suid bit on the executable.
xterm Xt error: Can't open display: s
xterm:  DISPLAY is not set

thanks

Last edited by sub320; 01-31-2016 at 08:59 PM.
 
Old 02-01-2016, 12:32 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
so that means there is no X environment available - or you have not set that DISPLAY variable (probably you only need to set it). top needs a terminal to work properly.
From the other hand you need to provide more information, it is not really enough to give any hints
 
Old 02-01-2016, 12:44 AM   #6
sub320
Member
 
Registered: Jan 2016
Posts: 116

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by pan64 View Post
so that means there is no X environment available - or you have not set that DISPLAY variable (probably you only need to set it). top needs a terminal to work properly.
From the other hand you need to provide more information, it is not really enough to give any hints
thanks reply ,

set that DISPLAY variable <<== would advise how to do it ?

besides , what infomation that I need to provide ? thanks
 
Old 02-01-2016, 12:50 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
if you have no idea what is that probably you won't need that.
Do you have graphical environment or just command line?
what do you want to achieve at all?
 
Old 02-01-2016, 01:25 AM   #8
sub320
Member
 
Registered: Jan 2016
Posts: 116

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by pan64 View Post
if you have no idea what is that probably you won't need that.
Do you have graphical environment or just command line?
what do you want to achieve at all?
we have command line only

just for testing only , we will implement another program later , would you help me for providing suggestion about how to do it , may be I may explain what my project target is .

Last edited by sub320; 02-01-2016 at 01:26 AM.
 
Old 02-01-2016, 01:42 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Maybe you could start by explaining why you picked top? Does it have similarities the 'other' program?
 
Old 02-01-2016, 01:47 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
Quote:
Originally Posted by sub320 View Post
we have command line only

just for testing only, ... would you help me for providing suggestion about how to do it , may be I may explain what my project target is .
Testing what? how should I give any suggestion without knowing any details?
 
Old 02-01-2016, 01:47 AM   #11
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
> may be I may explain what my project target is.

Quite an idea. I, for one, am not a clairvoyant.

Last edited by NevemTeve; 02-01-2016 at 01:49 AM.
 
Old 02-01-2016, 10:10 AM   #12
sub320
Member
 
Registered: Jan 2016
Posts: 116

Original Poster
Rep: Reputation: 3
thanks reply ,

what I just want is use the process of running the command "top" in background to eating up system resource , this is only testing purpose , is there any way to make it work ?


thanks

Last edited by sub320; 02-01-2016 at 10:12 AM.
 
Old 02-01-2016, 12:17 PM   #13
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Not sure about the others, but that didn't really clear anything up for me

Again, why does it need to be top?

If you want to eat all your system resources (not sure why you would want to on purpose), just create a recursive loop to call itself forever.
 
Old 02-01-2016, 06:58 PM   #14
sub320
Member
 
Registered: Jan 2016
Posts: 116

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by grail View Post
Not sure about the others, but that didn't really clear anything up for me

Again, why does it need to be top?

If you want to eat all your system resources (not sure why you would want to on purpose), just create a recursive loop to call itself forever.
thanks reply ,


"just create a recursive loop to call itself forever" << I am trying to do that but fail , as above the script , it pops error when run it , would advise how to modify it ? thanks
 
Old 02-01-2016, 07:55 PM   #15
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Here try this:

Code:
#!/bin/sh
# Eat up resources with "top"
function top {
TOP=100000
        if [[ "$1" -le "$TOP" ]]; then
                top $(($1 + 1)) "$2 $2"
        fi
}
top 1 "Seed string - Make this as long as you want depending on the amount of memory you have.";
I named the function top only to be as obfuscated as the question, so that you can call top recursively and eat up resources. You may rename it if that is too confusing.

I was nice and put a limit so that it will not (necessarily) run until your system melts down, but you will need to adjust it depending on your system resources and how much you want to waste them.

Save this to a script named resource_killer.sh, make it executable (chmod +x resource_killer.sh) then run it in the background with ./resource_killer.sh &.

It will consume CPU and memory resources until there are no more...

Offered as a complete freebie in order to facilitate having this thread marked as SOLVED.

Last edited by astrogeek; 02-01-2016 at 08:06 PM.
 
  


Reply



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
run script error ust Linux - Newbie 5 11-21-2012 09:52 AM
Run script error ust Linux - Newbie 2 03-25-2009 05:39 AM
error when tying to run python script(bash error?) shanenin Programming 5 01-10-2006 10:01 AM
run script error ust Linux - Software 3 01-04-2006 03:56 AM
run script error ust Linux - Software 7 09-09-2004 08:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:58 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
Open Source Consulting | Domain Registration