Viewing foreground process using ps

6,759

You might be confused because ps by default shows you the processes which are on the same terminal where ps is invoked, e.g. processes started from the same terminal window.

Try ps -u $LOGNAME or if you know the terminal names ps -t $THETTYNAME1,$THETTYNAME2. (The terminal names normally look like "ttyN" or "pts/N").

Share:
6,759

Related videos on Youtube

Jeff Schaller
Author by

Jeff Schaller

Unix Systems administrator http://www.catb.org/esr/faqs/smart-questions.html http://unix.stackexchange.com/help/how-to-ask http://sscce.org/ http://stackoverflow.com/help/mcve

Updated on September 17, 2022

Comments

  • Jeff Schaller
    Jeff Schaller over 1 year

    I can see the background process using ps. But Is there a way to view the foreground process? For example,

    $nohup process1 &

    then

    ps -ef | grep "process1"

    would display the process "process1" in execution. But the above command wouldn't show a foreground process executed like,

    $process2

    • Admin
      Admin over 13 years
      ps -ef shows all foreground processes for me. Which OS are you running on?
    • Admin
      Admin about 13 years
      Are you sure process2 is still running when you typing 'ps'? Maybe it's already done.
    • Admin
      Admin about 11 years
      By the time you get the prompt back, the foreground process is done.
    • Admin
      Admin over 2 years
      I feel this question is misleading; see the answer below for an explanation.
  • bahamat
    bahamat over 13 years
    ps - ef shows all processes, not just ones on "this" terminal.
  • Seamus
    Seamus over 2 years
    This answer is incorrect - or perhaps 'insufficiently qualified'. On my macOS (which uses a ps with a BSD heritage), issuing the ps command with no options lists processes on all 6 terminals (ttysxxx). man ps yields: The ps utility displays a header line, followed by lines containing information about all of your processes that have controlling terminals.