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

  • SEARCH
  • Home
  • 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 1093749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:52:14+00:00 2026-05-16T23:52:14+00:00

I have a need, for a python script I’m creating, to first get just

  • 0

I have a need, for a python script I’m creating, to first get just the PID of a process (based on its name) and then to get from that process, usings its PID, its time duration, which, from the printout below, would be “00:00:00”

root      5686     1  0 Sep23 ?        00:00:00 process-name

I am using this to get just the PID, by the process’s name:

ps -ef |grep `whoami`| grep process-name | cut -c10-15

So, this works fine and I am assuming that the cut parameters (-c10-15) would work universally as the placement of the PID shouldn’t change (I just got this from a snippet I found)

However, when I try to do something similar to get just the TIME value, such as this it returns it differently

ps -f 5686

returns:

root      5686     1  0 Sep23 ?        S      0:00 /path/to/process

So when I try a cut, as below, I don’t think it would work properly as I’m not sure the spacing on this return is consistent and also its showing the time value differently than before (not the original “00:00:00” style of printout.

ps -f 5686 | cut -c40-47

I’m using this in my python script to record the PID of a specific process type (by name) so that I can later shut down that instance of the progra when needed. Any advice on what I can do to correct my approach is appreciated

  • 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. Editorial Team
    Editorial Team
    2026-05-16T23:52:14+00:00Added an answer on May 16, 2026 at 11:52 pm

    Use the -o option to control what data is output and in what order.

    e.g.

    $ ps -o pid,time,comm
      PID     TIME COMMAND
     3029 00:00:01 zsh
    22046 00:00:00 ps
    

    or

    $ ps -o pid,time,comm --no-headers
     3029 00:00:01 zsh
    22046 00:00:00 ps
    

    This will make it easier to parse. I would suggest parsing the output with python using (pid, time, cmd) = result.split(2)

    Alternatively use the pgrep command to only list processes that match given criteria.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a process that pickles a dictionary using Python 3.2. I then need
I need a python script to perform a GET request on 2 urls. I
i have a python script which should invoke a .exe file to get some
I have a python script that takes a movie file name and it does
I have dates in a Python script that I need to work with that
I have a Python script and a C program and I need to pass
I have a Rails server which will need to run a python script at
I have a python script that calls a USB-based data-acquisition C# dotnet executable. The
I have a python script that calls a USB-based data-acquisition C# dotnet executable. The
I have made a Python script which calls functions based on user's input. Until

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.