LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 11-21-2016, 11:09 AM   #1
nuclear95
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Rep: Reputation: Disabled
Problem creating a script using Rss for total consumption memory


Hi,
i want to create a script that opens firefox,loads some urls from a txt file and then record some statistics such as the amount of instances that belongs to firefox and the total memory consumption(in MB) every 0.5 sec.i want the statistics to be written and saved in file.i know how to find the memory consumption ( grep /proc/"pid"/status VmRSS ) but i dont know how to do it every 0,5 sec and then write&save on file.

thank you for your time!!
 
Old 11-21-2016, 11:50 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
There is a utility named "watch" which you can use to run your script every 0.5 seconds. See its manual page for the details. You can write the output to a file using a redirection

But to convert it to RSS needs a bit more work, maybe with perl.
 
1 members found this post helpful.
Old 11-21-2016, 12:13 PM   #3
nuclear95
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thank you for your answer,but maybe you misundestood me.With Rss i mean Resident set size,not rss feed.if you can help me now i would appreciate it
 
Old 11-21-2016, 12:17 PM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Ok. How far have you gotten with "watch" and redirecting its output to a file?
 
Old 11-21-2016, 12:24 PM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Do you want to start firefox,open the URLS,then shut firefox down completely every .5 second?
 
Old 11-21-2016, 12:29 PM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by nuclear95 View Post
Thank you for your answer,but maybe you misundestood me.With Rss i mean Resident set size,not rss feed.if you can help me now i would appreciate it
"help me NOW???"

How about reading the "Question Guidelines" first?? We will be glad to help you...but if you want it 'now', then you need to hire someone. We volunteer our time here, so telling us to help you 'now' is plain rude. Also, 'help' means that YOU do work, and tell us where you're stuck, not post what you want and expect us to hand you a script.
 
Old 11-21-2016, 12:34 PM   #7
nuclear95
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
"help me NOW???"

How about reading the "Question Guidelines" first?? We will be glad to help you...but if you want it 'now', then you need to hire someone. We volunteer our time here, so telling us to help you 'now' is plain rude. Also, 'help' means that YOU do work, and tell us where you're stuck, not post what you want and expect us to hand you a script.
Sorry,i didnt mean that.i dont mean "now" as you think.(figure of speech)My fault,i didnt expressed it well.
 
Old 11-21-2016, 12:40 PM   #8
nuclear95
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by szboardstretcher View Post
Do you want to start firefox,open the URLS,then shut firefox down completely every .5 second?
i want to start firefox,open urls for txt file,create list with all pids of firefox,kill instances(all these on background) and i want to create a recording statistics function(or if you know a better way) that every 0.5 sec will create a list with the amount of instances that belong to firefox and the total consumption memory(with resident set size),and these data must be saved on a output file.

i am stuck on the last part with the recording function.Basically i dont know how to do it every 0.5 sec.
Thank you for your time

Last edited by nuclear95; 11-21-2016 at 12:41 PM. Reason: expand
 
Old 11-21-2016, 12:42 PM   #9
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Not a problem. Looks like you probably meant something like:

Quote:
With Rss i mean "Resident set size" - not "rss feed." If you can help me, now that I've explained better, I would appreciate it.
 
Old 11-21-2016, 12:47 PM   #10
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
If you can show the script that does the first part, we can probably help you out with the second part.
 
Old 11-21-2016, 12:48 PM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by nuclear95 View Post
i want to start firefox,open urls for txt file,create list with all pids of firefox,kill instances(all these on background) and i want to create a recording statistics function(or if you know a better way) that every 0.5 sec will create a list with the amount of instances that belong to firefox and the total consumption memory(with resident set size),and these data must be saved on a output file.

i am stuck on the last part with the recording function.Basically i dont know how to do it every 0.5 sec.
Thank you for your time
No problem...so, as asked previously; post what you have already done/written/tried, and we can assist.
 
Old 11-21-2016, 12:51 PM   #12
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by Turbocapitalist View Post
There is a utility named "watch" which you can use to run your script every 0.5 seconds. See its manual page for the details. You can write the output to a file using a redirection

But to convert it to RSS needs a bit more work, maybe with perl.
Quote:
Originally Posted by Turbocapitalist View Post
Ok. How far have you gotten with "watch" and redirecting its output to a file?
Quote:
Originally Posted by nuclear95 View Post
i want to start firefox,open urls for txt file,create list with all pids of firefox,kill instances(all these on background) and i want to create a recording statistics function(or if you know a better way) that every 0.5 sec will create a list with the amount of instances that belong to firefox and the total consumption memory(with resident set size),and these data must be saved on a output file.

i am stuck on the last part with the recording function.Basically i dont know how to do it every 0.5 sec.
Thank you for your time
Hi nuclear95, and welcome to LQ.

Can you please post some example output and illustrate what you have tried which gets you to this output. Please also update and indicate if you have tried the advice from Turbocapitalist?

Please note that it is difficult for persons to offer assistance for your problem if it appears that you are doing different attempts from the advice, we then have no idea which actions you are trying versus not.

Turbocapitalist also gave you a link for redirection which will help you with channeling the output of your command into a log file.

However if you have used a different command, or are writing a program to perform these actions, we have no real idea because you aren't posting any specifics about your attempts.
 
1 members found this post helpful.
Old 11-21-2016, 12:57 PM   #13
nuclear95
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
firefox &

while read line; do
firefox --new-tab "$line"
sleep 10s
done < /home/zografos/Desktop/urls.txt

pid=$!

sleep 30s

ps aux | grep firefox | awk '{print $2}'
sudo kill $pid

sleep 10s

ps aux | grep firefox | awk '{print $2}'
sudo kill -2 $pid

here is the 1st part of script
i forgot to mention that have to kill instances of firefox.
 
Old 11-21-2016, 01:03 PM   #14
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
First question. Isn't:

Code:
pid=$!
Capturing the pid of 'sleep 10s' instead of the firefox command? Seems like if you wanted a pid list, you would create it in the loop so you capture each pid created.
 
1 members found this post helpful.
Old 11-21-2016, 02:03 PM   #15
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
Code:
#Read the file by line
while read line; do
    #Will open URL in a tab (background it)
    firefox --new-tab "$line" &
    #Sleep between tab open
    sleep 2
    #Find number of firefox PID's running, will be 1 with tabs.
    pgrep firefox | wc -l >> stats.txt
    #RAM stats to file
    free -t >> stats.txt
    #Seperatpr
    echo "------New Tab------" >> stats.txt    
#File to read
done < /home/zografos/Desktop/urls.txt
Leave out --new-tab if you want to open a new instance of firefox each time. Add whatever else you want in that loop.
 
  


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
[SOLVED] IS the memory consumption ok or not ok and why? ITareliteralyMyInitials Linux - Newbie 4 08-18-2015 03:18 AM
Total used memory a lot higher than sum of RSS kazabubu Linux - General 15 07-26-2010 09:51 AM
Problem with memory consumption vidyavati Linux - Embedded & Single-board computer 1 07-09-2009 12:37 PM
Memory Consumption of 10.2 naparhi Slackware 4 08-27-2006 03:10 AM
Memory/Swap consumption problem with squid and kget drumvudu SUSE / openSUSE 0 02-03-2005 08:10 AM

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

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