LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 10-16-2018, 02:21 PM   #1
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Rep: Reputation: Disabled
command explanation


for test in $(seq 2); do cat /dev/urandom > /dev/null ; done what does for loop do in contnious stream like that as long the script runs endlessly (isn't it?) why do i have to loop for more than a time

ps : that's a command given by someone here in purpose to stress test my cpu
 
Old 10-16-2018, 02:54 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 7,992
Blog Entries: 13

Rep: Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443
I suppose /dev/urandom will always stream out until you exit that command.

Ask them why they feel it has a loop.

And, remove the loop and see if it behaves differently.
 
Old 10-16-2018, 03:19 PM   #3
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
I suppose /dev/urandom will always stream out until you exit that command.

Ask them why they feel it has a loop.

And, remove the loop and see if it behaves differently.
then why the guy recommended me to loop
 
Old 10-16-2018, 03:27 PM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,177

Rep: Reputation: 531Reputation: 531Reputation: 531Reputation: 531Reputation: 531Reputation: 531
Perhaps they meant two background processes?
Code:
for test in $(seq 2); do cat /dev/urandom > /dev/null & done
The ampersand makes the difference.
 
Old 10-16-2018, 03:55 PM   #5
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by MadeInGermany View Post
Perhaps they meant two background processes?
Code:
for test in $(seq 2); do cat /dev/urandom > /dev/null & done
The ampersand makes the difference.
why they should be ran in the background i know that wouldn't stop it so i will unplug power if it loops endlesly i know as well this is a trick

Last edited by shlomo.hovir; 10-16-2018 at 03:56 PM.
 
Old 10-16-2018, 05:13 PM   #6
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,614

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Quote:
Originally Posted by shlomo.hovir View Post
then why the guy recommended me to loop
Maybe ask the guy who made that recommendation.

Quote:
Originally Posted by shlomo.hovir View Post
why they should be ran in the background i know that wouldn't stop it so i will unplug power if it loops endlesly i know as well this is a trick
When running a job in the background that you want to terminate, use the ps command to get the PID of the job, then
Code:
kill -9 <pid of job>
or use killall to kill by job name.
See man killall
 
Old 10-16-2018, 05:20 PM   #7
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,270

Rep: Reputation: 851Reputation: 851Reputation: 851Reputation: 851Reputation: 851Reputation: 851Reputation: 851
Quote:
Originally Posted by shlomo.hovir View Post
why they should be ran in the background
The goal was to stress the CPU. One process loads the CPU a little. Two processes load the CPU more, but only one process can run in the foreground. It therefore makes sense to run the processes in the background.

An alternative would be running each processes from a different shell. That is OK with two processes, but if you want to stress your CPU even more, it soon becomes unmanageable.
 
Old 10-16-2018, 07:06 PM   #8
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
The goal was to stress the CPU. One process loads the CPU a little. Two processes load the CPU more, but only one process can run in the foreground. It therefore makes sense to run the processes in the background.

An alternative would be running each processes from a different shell. That is OK with two processes, but if you want to stress your CPU even more, it soon becomes unmanageable.

thats just a void !!!!!
i don't beleive u
 
Old 10-16-2018, 07:08 PM   #9
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Original Poster
Rep: Reputation: Disabled
Angry

Quote:
Originally Posted by shlomo.hovir View Post
thats just a void !!!!!
i don't beleive u
im just sure thats a trap is used to stress the cpu enough to kill it then jump to other one
go play away

Angry Angry Angry Angry Angry Angry Angry Angry
 
Old 10-16-2018, 08:44 PM   #10
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 523

Rep: Reputation: 314Reputation: 314Reputation: 314Reputation: 314
It is not a trap. It will not kill the processor. It will warm it up a little.

I think the reason for the loop is to load multiple CPUs. If your computer has 2 CPUs, then you need 2 processes to fully load it.

Here I will show you how to start and stop the processes:
Code:
$ for test in $(seq 2); do cat /dev/urandom > /dev/null & done
[1] 14070
[2] 14071
$ kill 14070
$ kill 14071
[1]-  Terminated              cat /dev/urandom > /dev/null
$ 
[2]   Terminated              cat /dev/urandom > /dev/null
$
After the first line, I could see in another window that both of my CPUs were running at 100%. Each kill command stopped one of the processes. After that, both CPUs were idle.

Last edited by Beryllos; 10-16-2018 at 08:46 PM.
 
Old 10-16-2018, 10:09 PM   #11
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,270

Rep: Reputation: 851Reputation: 851Reputation: 851Reputation: 851Reputation: 851Reputation: 851Reputation: 851
Quote:
Originally Posted by shlomo.hovir View Post
im just sure thats a trap is used to stress the cpu enough to kill it then jump to other one
go play away

Angry Angry Angry Angry Angry Angry Angry Angry
Sorry. I just had to try.

Here is a suggestion. To protect your CPU, just switch the computer off. Or, if this is not an option, just run half a process:
Code:
for i in 0.5
do
    cat /dev/urandom > /dev/null &
done
See? It remains cool.
 
Old 10-17-2018, 02:35 PM   #12
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
Sorry. I just had to try.

Here is a suggestion. To protect your CPU, just switch the computer off. Or, if this is not an option, just run half a process:
Code:
for i in 0.5
do
    cat /dev/urandom > /dev/null &
done
See? It remains cool.
doesn't work
 
  


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
ls */ explanation zeusys Linux - Newbie 3 08-17-2011 11:41 PM
[SOLVED] Need an explanation of here scripts as well as the "cat" command UNGR Linux - Newbie 11 08-13-2011 10:08 AM
Need explanation for TOP command bkarthick Linux - Newbie 3 06-02-2011 08:37 AM
Netstat command output explanation. nobitavn Linux - Newbie 8 10-13-2010 11:21 AM
I Could Use An Explanation winger Linux - General 3 04-13-2002 10:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:41 AM.

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