ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 .
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?
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
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
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
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?
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 .
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 ?
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
#!/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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.