LinuxQuestions.org
Review your favorite Linux distribution.
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-23-2017, 12:11 AM   #1
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Rep: Reputation: Disabled
Unhappy Linux ps command help!


Hey guys, long time lurker finally hitting a wall!

I've got two questions I need to figure out for my homework.
First one asks me to list the process id number and total CPU time for each process on the system. I'm assuming I would use 'ps' and somehow combine it with 'grep'?
I'm currently using Putty to access an server, when I run just 'ps' it gives me two lines.

10585 pts/34 00:00:00 bash
10902 pts/34 00:00:00 ps

I'm assuming the TIME collumn is the cpu run time but why does it come up as 0?

My next question involves the same info but instead I only need to display the process id number and total CPU time for each process associated with my userid

Thank you for any help!

EDIT: If you could provide an explanation or perhaps links as well that would be great, I want to actually understand what i'm doing not just cheat through it.

Last edited by goofygoober; 11-23-2017 at 12:48 AM. Reason: extra info
 
Old 11-23-2017, 12:17 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,821

Rep: Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084
Hi and welcome goofygoober

First thing you might want to do is consider your question as it has little to do with ssh (even though you might be connecting that way)

As it is homework (and thanks for being up front about it) I would suggest the first thing you will want to do is have a look at the man page for ps
It is very well detailed and even has some very helpful examples, some of which will even go towards helping with your answers

See how you go and then come back with more information on where your stuck
 
Old 11-23-2017, 12:42 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,678
Blog Entries: 3

Rep: Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918
I'd also direct your attention specifically to the -o option for ps in the manual page:

Code:
man ps
man man
Depending on how much you want to digress, you might also look at pgrep and top too.

Code:
man pgrep
man top
By the way, it's possible to edit the title of your post so that it reflects the question. I was kind of hoping for a nice SSH question but this one is clearly about ps instead.
 
Old 11-23-2017, 12:54 AM   #4
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
I'd also direct your attention specifically to the -o option for ps in the manual page:

Code:
man ps
man man
Depending on how much you want to digress, you might also look at pgrep and top too.

Code:
man pgrep
man top
By the way, it's possible to edit the title of your post so that it reflects the question. I was kind of hoping for a nice SSH question but this one is clearly about ps instead.
Title has been changed!

I think I figured out the pid portion
using 'ps -o "%p %C" i get an output that shows
PID %CPU
10585 0.0
11246 0.0

seems the process id's are being listed properly but why does CPU still come up as 0.0??
 
Old 11-23-2017, 01:04 AM   #5
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
after rereading the question i've changed my command to
ps -eo "%p %C" since im required to show the processes for the system
the problem also asks that I insert the output of the command below my answer....theres a good few hundred lines coming up do I need to just copy them all onto this text file (that I turn in with the questions/my answers) this is the first time we've had to insert the output, am i just misunderstanding what it's asking for?
 
Old 11-23-2017, 01:23 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,678
Blog Entries: 3

Rep: Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918
Be sure to take a look at the section "STANDARD FORMAT SPECIFIERS" in the manual page for other keywords. The CPU time will be in some format like [DD-]hh:mm:ss

As for the output, what does the assignment say you should produce? If it is really asking for the full list, that will be a long list, especially if there are multiple users using the system.
 
Old 11-23-2017, 01:44 AM   #7
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Be sure to take a look at the section "STANDARD FORMAT SPECIFIERS" in the manual page for other keywords. The CPU time will be in some format like [DD-]hh:mm:ss

As for the output, what does the assignment say you should produce? If it is really asking for the full list, that will be a long list, especially if there are multiple users using the system.
I've looked in that section but the example they use is a bit confusing as they dont explain what the command is actually doing.

ps -eo pid,user,args --sort user

is what they provide. I do understand that if i wanted to see the processes CPU uptime then I would use 'ps -eo bsdtime' this gives the same result (for the cpu) as the one that I came up with originally.

My goal is to list the process id's and the CPU time
ps -eo "%p %C"
is giving me that, but the CPU time is just coming up as 0.0
 
Old 11-23-2017, 01:47 AM   #8
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Be sure to take a look at the section "STANDARD FORMAT SPECIFIERS" in the manual page for other keywords. The CPU time will be in some format like [DD-]hh:mm:ss

As for the output, what does the assignment say you should produce? If it is really asking for the full list, that will be a long list, especially if there are multiple users using the system.
Actually, that seems to work. Not all of the processes are at 0.0, a few for example have 0.8 as their CPU time.

My question now is, is this normal? for so many of the system processes to just be 0.0? I'd say 95% of them are like that.
 
Old 11-23-2017, 01:55 AM   #9
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,678
Blog Entries: 3

Rep: Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918
Ok. The manual pages are technical references not tutorials so in the begining they need to be supplemented by guides, tutorials, or forums. However, it is good practice to look things up in them. So please find the descriptions for -e and the --sort there:

The -e means to show all processes on the system, even the ones that are not yours.

The --sort obviously sorts, but you can give that option its own options to specify which keys to sort on.

The -o option takes one or more arguments and that is the part relevant to your task. Scroll down to the section mentioned above in #6 and look for the descriptions of the different options.

(The quality of the manual pages does vary quite a bit and even the good ones need time to become familiar.)

Last edited by Turbocapitalist; 11-23-2017 at 01:56 AM.
 
Old 11-23-2017, 02:10 AM   #10
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Ok. The manual pages are technical references not tutorials so in the begining they need to be supplemented by guides, tutorials, or forums. However, it is good practice to look things up in them. So please find the descriptions for -e and the --sort there:

The -e means to show all processes on the system, even the ones that are not yours.

The --sort obviously sorts, but you can give that option its own options to specify which keys to sort on.

The -o option takes one or more arguments and that is the part relevant to your task. Scroll down to the section mentioned above in #6 and look for the descriptions of the different options.

(The quality of the manual pages does vary quite a bit and even the good ones need time to become familiar.)
Yeah that makes sense.
I understand that section now, i'm just still fairly new when it comes to combining two different conditions, for example If i wanted to use '-eo' and define -o with "%p %C" but then I also wanted to define -o with tty, just for example, on the same line.
Anyways, I've figured out the first problem.

Now what I need to do is #1 show the same thing, pid and cpu time, but only for processes under my userid, and #2 show only the process with the most amount of cpu time.
 
Old 11-23-2017, 02:15 AM   #11
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Ok. The manual pages are technical references not tutorials so in the begining they need to be supplemented by guides, tutorials, or forums. However, it is good practice to look things up in them. So please find the descriptions for -e and the --sort there:

The -e means to show all processes on the system, even the ones that are not yours.

The --sort obviously sorts, but you can give that option its own options to specify which keys to sort on.

The -o option takes one or more arguments and that is the part relevant to your task. Scroll down to the section mentioned above in #6 and look for the descriptions of the different options.

(The quality of the manual pages does vary quite a bit and even the good ones need time to become familiar.)
So I think I was able to figure out the showing biggest process portion
ps -eo %p %C" | sort -nrk 2,2 | head -n 1

With the process coming up as 1.8 im assuming the system is converting it from time>decimal, am I correct?

If so, now I just need to figure out how to sort out only processes running under my userid.
 
Old 11-23-2017, 09:10 AM   #12
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
Could use the help if anyone has any ideas
 
Old 11-23-2017, 09:18 AM   #13
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,678
Blog Entries: 3

Rep: Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918
Quote:
Originally Posted by goofygoober View Post
So I think I was able to figure out the showing biggest process portion
ps -eo %p %C" | sort -nrk 2,2 | head -n 1

With the process coming up as 1.8 im assuming the system is converting it from time>decimal, am I correct?

If so, now I just need to figure out how to sort out only processes running under my userid.
I would use cputime instead of %C because that seems to meet your described requirements better.

As for limiting the output to processes owned just by one user, check the manual page again and scroll down to the options just below --tty. The --tty option is not relevant but the options that are described there next are.
 
Old 11-23-2017, 09:29 AM   #14
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
I would use cputime instead of %C because that seems to meet your described requirements better.

As for limiting the output to processes owned just by one user, check the manual page again and scroll down to the options just below --tty. The --tty option is not relevant but the options that are described there next are.
Alright, i'm seeing (--user userlist)
How could I use that in combo with my earlier command? another reason I wish there was more examples =p
ps -eo "%p %C" --user xxxx wouldn't work i'm sure ( not currently home can't check)
 
Old 11-23-2017, 09:38 AM   #15
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,678
Blog Entries: 3

Rep: Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918
Ok. When you get back to a computer you can test a few things. One is if -e and -u (or --user) can be used at the same time or not. Another is a number of variations on using -o to set user-defined formats.

In the longer term, you might consider moving the legacy OS into a virtual machine such as Virtualbox and running it from there so that you have a normal Linux distro for your main activities. That will give you the ability to test whenever you want. Also by having the legacy system in a virtual machine you can keep snapshots of it so that when it curdles you can roll back to a known good version with a click or two.
 
  


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
from Win XP, remotely execute a command on Linux using ssh lothario Linux - Software 3 06-21-2008 05:59 PM
Login to Linux from Windows command prompt through ssh sysadmn Linux - Networking 1 03-25-2005 04:13 AM

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

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