LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Checking Processes Running in the Background and Showing Them (https://www.linuxquestions.org/questions/linux-server-73/checking-processes-running-in-the-background-and-showing-them-831389/)

Hi_This_is_Dev 09-10-2010 09:39 AM

Checking Processes Running in the Background and Showing Them
 
Hi,


While executing df command on an AIX Console, by mistake I ended the line with an ampersand:

Code:

bash-3.2$ df -g /etl*&
[1] 94696
bash-3.2$ Filesystem    GB blocks      Free %Used    Iused %Iused Mounted on
/dev/hd4          2.00      1.83    9%    7062    2% /
df -g /etl*
Filesystem    GB blocks      Free %Used    Iused %Iused Mounted on
/dev/hd4          2.00      1.83    9%    7062    2% /
[1]+  Done                    df -g /etl*

Since it is a Production Sever and I am not supposed to run any such background job. I typed this command:

Code:

bash-3.2$ jobs
which returned nothing.

Then I tried:

Code:

bash-3.2$ fg
bash: fg: current: no such job
bash-3.2$

I also checked if the df was still running in the background:

Code:

bash-3.2$ ps
    PID    TTY  TIME CMD
 145150  pts/4  0:00 ps
 147334  pts/4  0:00 bash
 261518  pts/4  0:00 -ksh
bash-3.2$

Code:

bash-3.2$ ps -f
    UID    PID  PPID  C    STIME    TTY  TIME CMD
me 197516 338958  1 10:03:56  pts/4  0:00 bash
me 295904 197516  2 10:35:38  pts/4  0:00 ps -f
me 338958 224462  0 10:03:54  pts/4  0:00 -ksh
bash-3.2$


So, what do you think? Am I on the safe side already? Or the process:

Code:

df -g /etl*&
might still be running in the background?

Please advise.

druuna 09-10-2010 09:42 AM

Hi,

You are safe:
Code:

bash-3.2$ df -g /etl*&
[1] 94696
bash-3.2$ Filesystem    GB blocks      Free %Used    Iused %Iused Mounted on
/dev/hd4          2.00      1.83    9%    7062    2% /
df -g /etl*
Filesystem    GB blocks      Free %Used    Iused %Iused Mounted on
/dev/hd4          2.00      1.83    9%    7062    2% /
[1]+  Done                    df -g /etl*

The blue part tells you that the job has finished.

Hope this helps.

Hi_This_is_Dev 09-10-2010 10:11 AM

Quote:

Originally Posted by druuna (Post 4093514)
Hi,

You are safe:
Code:

bash-3.2$ df -g /etl*&
[1] 94696
bash-3.2$ Filesystem    GB blocks      Free %Used    Iused %Iused Mounted on
/dev/hd4          2.00      1.83    9%    7062    2% /
df -g /etl*
Filesystem    GB blocks      Free %Used    Iused %Iused Mounted on
/dev/hd4          2.00      1.83    9%    7062    2% /
[1]+  Done                    df -g /etl*

The blue part tells you that the job has finished.

Hope this helps.


Hey Thanks for reconfirming what I was thinking of... that a background should stop at some point when it has finished executing.

Thanks again!

By the way, how are you doing? :)

druuna 09-10-2010 10:24 AM

Hi,

Quote:

Hey Thanks for reconfirming what I was thinking of... that a background should stop at some point when it has finished executing.
After a background job stops it reports back that is has stopped. This reporting back happens when the terminal is free to use again, which was immediate in your example but can take a while. It also tells you which job/command finished.

Try this harmless experiment:
Code:

$ sleep 4 &
[1] 14860
$ sleep 7
[1]+  Done                    sleep 4
$

The first sleep is put in the background and tells you its jobnumber [1] and PID 14860. If you type sleep 7 immediately after that message and press enter it will take 7 seconds before you get your prompt back. Because the first sleep has finished it will output this directly after sleep 7 is done. It tells you the job number again [1]+, that it is ready Done and what was done sleep 4

Quote:

By the way, how are you doing?
Quite well, Friday evening is just about to start. Weekend is approaching fast ;)

Hi_This_is_Dev 09-11-2010 03:21 PM

Quote:

Originally Posted by druuna (Post 4093557)
Try this harmless experiment:
Code:

$ sleep 4 &
[1] 14860
$ sleep 7
[1]+  Done                    sleep 4
$

The first sleep is put in the background and tells you its jobnumber [1] and PID 14860. If you type sleep 7 immediately after that message and press enter it will take 7 seconds before you get your prompt back. Because the first sleep has finished it will output this directly after sleep 7 is done. It tells you the job number again [1]+, that it is ready Done and what was done sleep 4


Thanks! I experimented with those commands and got the concept.

Quote:

Quite well, Friday evening is just about to start. Weekend is approaching fast ;)
When I posted the question I was at office and it was Friday night yesterday. Now it is getting 2 am which means it is already Sunday here. I had off today! But tomorrow I have office. I love to be at my work desk rather than staying home!

By the way, you use LFS distribution. So, did you build it yourself? I mean, have you experimented building your own Linux Distro?

Anyways, have a nice weekend!

druuna 09-11-2010 03:29 PM

Hi,
Quote:

Originally Posted by Hi_This_is_Dev (Post 4094643)
Thanks! I experimented with those commands and got the concept.

You're welcome :)
Quote:

By the way, you use LFS distribution. So, did you build it yourself? I mean, have you experimented building your own Linux Distro?
Yes, I've been running (B)LFS with extra packages not mentioned in either of those 2 for several years now. Bit more work than installing a real distro but I find it worth it in the end (more control and no pampering being the main reasons).

Enjoy the rest of your weekend!


All times are GMT -5. The time now is 10:43 PM.