LinuxQuestions.org
Review your favorite Linux distribution.
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 08-20-2005, 03:37 AM   #1
donotexpert
LQ Newbie
 
Registered: Aug 2005
Location: thai
Posts: 4

Rep: Reputation: 0
help me(my homework) please!


a)List the number of unique users that has active processes.
b)List the number of active processes for each of the users in (a).
c)Execute “ps–ef> ps.out”command and enclose in the report. Determine the total number of CPU load in “ps.out”.
d)Determine total memory usage for each user.

you can helping me I don't know to begin this ploblem ?
I know it's easy for you
 
Old 08-20-2005, 04:12 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Ooooh... homework help aye?
Listen: you have to do your own homework.
However: I can help you understand your homework questions and put you on the right track OK? (And shame on anyone who just supplies the method...)

in terminal, "man ps", will tell you all about what ps does and is, and supplies example of how to use it. English language will be a problem for you here - but care will help you: this is one of the simpler man pages.

$ ps
will display a list of running processes to stdout (the terminal). For eg. On my system I get
Code:
[~]$ ps
  PID TTY          TIME CMD
 4179 pts/1    00:00:00 bash
 4827 pts/1    00:00:00 ps
You can get a record in a text file by typing
$ ps > foo.txt
... and you'll fine a file called "foo.txt" with the same stuff in it in whatever directory you were in when you typed the line. Of course, it is useful to choose a discriptive file name... like "ps.out" suggested by the teacher.

ps can be run with various options to alter the output.
for eg: $ps -f gives you the "full" description of the processes. Again, for me, this is:
Code:
 [~]$ ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
simon     4179  5619  0 20:01 pts/1    00:00:00 bash
simon     4859  4179  0 21:11 pts/1    00:00:00 ps -f
See the difference?

the -e flag gives you "everything"... a list of all processes running on the machine. This can be rather long so I'll not give you an example.

$ps -e -f
is the same as
$ps -ef
and gives you a full list of all the processes.

This should be enough to start you off.
What you need in written in the man page for ps.
Good luck.
 
Old 08-20-2005, 04:30 AM   #3
donotexpert
LQ Newbie
 
Registered: Aug 2005
Location: thai
Posts: 4

Original Poster
Rep: Reputation: 0
thank alot and I want to know how to creat for gcc program

exsample

#include <stdlib.h>
#include <stdio.h>
int main()
{
printf(“Running ps with system\n”);
system(“ps -u”);
printf(“Done.\n”);
exit(0);
}


it show
Running ps with system
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2457 0.0 0.4 1740 404 tty1 Ss+ Aug16 0:00 /sbin/mingetty tt
root 2458 0.0 0.4 1952 408 tty2 Ss+ Aug16 0:00 /sbin/mingetty tt
root 2461 0.0 0.4 2572 408 tty3 Ss+ Aug16 0:00 /sbin/mingetty tt
root 2462 0.0 0.4 2372 408 tty4 Ss+ Aug16 0:00 /sbin/mingetty tt
root 2570 0.0 0.4 3012 408 tty5 Ss+ Aug16 0:00 /sbin/mingetty tt
root 2583 0.0 0.4 1564 408 tty6 Ss+ Aug16 0:00 /sbin/mingetty tt
root 3041 0.0 1.4 5368 1392 pts/1 Ss Aug16 0:00 -bash
root 3083 37.0 0.8 2580 772 pts/1 R+ 01:31 0:00 ps -u
Done

I want to use this program that show
only user

how to make this program ?
 
Old 08-20-2005, 05:23 AM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Run your program as normal user
 
Old 08-20-2005, 06:26 AM   #5
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
donotexpert: when you use linux, you should always be a normal user. Never run anything as root that you don't have to.

BTW: you realise this is easier to run with a script? Something like:
Code:
#!/bin/sh
echo -n "Running ps from the $0 script."
ps -u
echo "Done."
write this in a text file filename.sh, change the permissions so it is executable by you.
type ./filename.sh to execute it. To change user, you can add "su $1" and "exit" before and after the "ps -u" command. Then run the script with "./filename username". (See "man su" to see what it is about.) Of course, you'll need the users password.

You could also use sudo instead of su (it's tougher to set up but easier to use once it is.)

Or, of course, you could read the ps man page and it will tell you how to use ps -u to print the processes run by another user... (Remember, I'm not actually going to do your homework for you...)

Last edited by Simon Bridge; 08-20-2005 at 06:29 AM.
 
  


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
Help on Homework... Cant find .bashrc maravillasc Linux - Newbie 11 10-17-2005 09:39 PM
Linux homework Ghstfce Linux - General 7 09-09-2005 04:39 AM
homework help louce Linux - Newbie 3 09-04-2005 08:00 PM
please help my homework again donotexpert Programming 7 08-23-2005 10:26 AM
Need homework help! bumstickie Linux - Newbie 3 10-28-2002 04:37 AM

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

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