473,765 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding the number of UIDs on unix

Hey everyone,
(Sorry about the first message if it made it - i got cut off
early). I have a homework problem for my Operating Systems class. I
am supposed to use a command such as "ps -aux" and return "N number of
users, M number of processes". How am I to go about doing this? I am
not very familiar with string parsing in c++, is this the only way? I
am talking about getting the output from "ps -aux" and parsing it to
retrieve the number of unique UIDs.

Any suggestions would be appreciated. Thank you in advance!

Blaine
University of Cincinnati

Apr 12 '07 #1
2 1594
frikk wrote:
Hey everyone,
(Sorry about the first message if it made it - i got cut off
early). I have a homework problem for my Operating Systems class. I
am supposed to use a command such as "ps -aux" and return "N number of
users, M number of processes". How am I to go about doing this? I am
not very familiar with string parsing in c++, is this the only way? I
am talking about getting the output from "ps -aux" and parsing it to
retrieve the number of unique UIDs.
Please see the FAQ, in particular 5.2 and 5.3.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

However, I'm feeling nice.

1. RTFM to find out the format from ps -aux
2. Read into a vector of strings
3. Parse the strings into subfields (note: stringstreams may be useful
here).
4. Process the data, using the knowledge gained in step 1.
Apr 12 '07 #2
frikk wrote:
Hey everyone,
(Sorry about the first message if it made it - i got cut off
early). I have a homework problem for my Operating Systems class. I
am supposed to use a command such as "ps -aux" and return "N number of
users, M number of processes". How am I to go about doing this? I am
not very familiar with string parsing in c++, is this the only way? I
am talking about getting the output from "ps -aux" and parsing it to
retrieve the number of unique UIDs.
Sounds like you're working on a UNIX system. As such, the newsgroup
comp.unix.progr ammer is likely the best one for your question.

Some hints along the way, ps is a user command. You'll need to find a
way to capture the output that would normally be displayed by the
shell. Perhaps something like popen() will right for you. They can help
you with that there.

I've gone ahead and crossposted this to comp.unix.progr ammer and set
followups.

Once you solve the problem of reading the output, you may have some
programming questions that would be appropriate for this newsgroup.


Brian
Apr 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
12368
by: Hal Vaughan | last post by:
I want to have a config file for my program, which means I need to know where the config file is. If I type: java myclass and it runs myclass.class, is there any way to obtain the location of the file myclass.class? Will this work if it's run from a relative path, like: java ../progs/myclass
46
2536
by: dawn | last post by:
Hi all, I am now working on a C program under Unix. The requirement for the program is that: A file name is passed to program as a parameter. The program will Find files under a specified directory. The matched file must have the same content with the given file. It does not matter whether the filenames are the same. It is easy to find file that has the same name with given file, but may be hard to find the files that with the same...
9
10324
by: minil | last post by:
Hi any c function in linux to return size of directory (Including its files & subdirectories & its files).. I can stat() only files . not for directories. please reply me soon Thanks in advance
1
2971
by: wobbles | last post by:
Hi Everyone, I have a server which reads information from a "server.exe.config" file and a client that also reads from its "client.exe.config" file. If the server location or the port number changes I'd like to write (using streamwriter) a new config file for the client app. So I have a few questions: 1. Is "writing" my own config file (for the client) a bad approach. If
20
10861
by: Joel Hedlund | last post by:
Hi all! I use python for writing terminal applications and I have been bothered by how hard it seems to be to determine the terminal size. What is the best way of doing this? At the end I've included a code snippet from Chuck Blake 'ls' app in python. It seems to do the job just fine on my comp, but regrettably, I'm not sassy enough to wrap my head around the fine grain details on this one. How cross-platform is this? Is there a more...
13
2013
by: athiane | last post by:
I want a way to parse out all function names that appear in a couple of C files. When the parsing logic finds a function name in a file, it should print out the Function name, line number and file in which the Function was found. What approach should i follow to tackle this problem ? Is there any option in the gcc compiler that prints out this information ?
12
2432
by: Sankar | last post by:
Dear all, I am programming in Linux , wherein I need to know a couple of things. 1) Does an API exist that can copy file onto another file ( an API equivalent of 'cp') ? 2) Is there an API that tells me the disk usage ( equivalent for cmdline
21
3038
by: Tom Gur | last post by:
Hi, It's seems that csh and tcsh acts a bit different when handling special characters in quotes. i.e: if i'll supply my program with the following arguments: -winpath "c:\\temp\\" tcsh will take it as -winpath "c:\temp\" and csh will take it literally (with the double-slashes). Is there a way for me to know what shell is currently running my
11
4922
by: John | last post by:
Is there a way to find the number of processors on a machine (on linux/ windows/macos/cygwin) using python code (using the same code/cross platform code)?
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.