# Viewing foreground process using ps

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

## migrated from stackoverflow.comJan 19 '11 at 14:52

This question came from our site for professional and enthusiast programmers.

• ps -ef shows all foreground processes for me. Which OS are you running on? – bahamat Jan 19 '11 at 19:49
• Are you sure process2 is still running when you typing 'ps'? Maybe it's already done. – Huang F. Lei Mar 19 '11 at 6:33
• By the time you get the prompt back, the foreground process is done. – vonbrand Mar 14 '13 at 1:15

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"). • ps - ef shows all processes, not just ones on "this" terminal. – bahamat Jan 19 '11 at 19:51 Weird, the ps command allows you to monitor the status of all active processes, both foreground and background. For example, I start the following process in a first shell: $ startNetworkServer
Security manager installed using the Basic server security policy.
Apache Derby Network Server - 10.3.2.1 - (599110) started and ready to accept connections on port 1527 at 2010-06-18 14:14:33.277 GMT


And in another shell:

\$ ps aux  | grep NetworkServer | grep -v grep

The process is listed as expected (and the + shows that it is in the foreground process group).