Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 153681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:50:39+00:00 2026-05-11T09:50:39+00:00

On Linux, the command ps aux outputs a list of processes with multiple columns

  • 0

On Linux, the command ps aux outputs a list of processes with multiple columns for each stat. e.g.

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND ... postfix  22611  0.0  0.2  54136  2544 ?        S    15:26   0:00 pickup -l -t fifo -u apache   22920  0.0  1.5 198340 16588 ?        S    09:58   0:05 /usr/sbin/httpd 

I want to be able to read this in using Python and split out each row and then each column so they can be used as values.

For the most part, this is not a problem:

ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE).communicate()[0] processes = ps.split('\n') 

I can now loop through processes to get each row and split it out by spaces, for example

sep = re.compile('[\s]+') for row in processes:     print sep.split(row) 

However, the problem is that the last column, the command, sometimes has spaces in. In the example above this can be seen in command

pickup -l -t fifo -u 

which would be split out as

['postfix', '22611', '0.0', '0.2', '54136', '2544', '?', 'S', '15:26', '0:00', 'pickup', '-l', '-t', 'fifo', '-u'] 

but I really want it as:

['postfix', '22611', '0.0', '0.2', '54136', '2544', '?', 'S', '15:26', '0:00', 'pickup -l -t fifo -u'] 

So my question is, how can I split out the columns but when it comes to the command column, keep the whole string as one list element rather than split out by spaces?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:50:39+00:00Added an answer on May 11, 2026 at 9:50 am

    Use the second parameter to split which specifies the maximum number of fields to split the string into. I guess you can find the number by counting the number of fields in the first line, i.e. the column titles.

    ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE).communicate()[0] processes = ps.split('\n') # this specifies the number of splits, so the splitted lines # will have (nfields+1) elements nfields = len(processes[0].split()) - 1 for row in processes[1:]:     print row.split(None, nfields) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 107k
  • Answers 108k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Original answer: I'm not sure if you will like how… May 11, 2026 at 9:09 pm
  • Editorial Team
    Editorial Team added an answer When you create the persistent store coordinator, if you are… May 11, 2026 at 9:09 pm
  • Editorial Team
    Editorial Team added an answer Yep, works fine. Make sure that you install it before… May 11, 2026 at 9:09 pm

Related Questions

Using the ClearCase find command, how do I find all files in a directory
I've done quite a bit of programming on Windows but now I have to
I wrote a program in C with Ubuntu Linux and now I need to
Is it possible to embed flash in a mono Application? Preferably would be similar

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.