LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Different PID with & and ps (https://www.linuxquestions.org/questions/linux-general-1/different-pid-with-and-and-ps-761590/)

Sarah_Student 10-13-2009 08:13 AM

Different PID with & and ps
 
Hi
I use Linux Suse Enterprise server 10.
I have installed mc on it.
While sending mc to background with mc & I receive a PID for example 7521 but when I use ps command to check the active processes, this PID (7521) is assigned to bash process and mc ID has changed to some thing more, for example 7525.
Can any one explain me the reason? For other processes that I have checked, the assigned PID is same.
Thanks in advance.

catkin 10-13-2009 11:04 AM

Please post the line you are using to send mc to background with mc &

Sarah_Student 10-18-2009 01:26 AM

I use these lines...
mc &
[1] 5704
ps
5502 pts/1 00:00:00 bash
5704 pts/1 00:00:00 bash
570B pts/1 00:00:00 mc
5710 pts/1 00:00:00 ps
[1]+ stopped mc

catkin 10-18-2009 06:42 AM

Intriguing. Here's equivalent from Slackware 13.0 (sorry -- don't know how to find version of mc; the -V option doesn't give it, grepping all the /var/log/packages files for /usr/bin/mc doesn't find it ...)
Code:

c:~$ mc &
[1] 7478
c:~$ ps
                        PID TTY          TIME CMD
 7116 pts/2    00:00:00 bash
 7478 pts/2    00:00:00 mc
 7481 pts/2    00:00:00 ps

[1]+  Stopped                mc
c:~$ type mc
mc is hashed (/usr/bin/mc)
c:~$ file /usr/bin/mc
/usr/bin/mc: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped


itz2000 10-18-2009 01:15 PM

Code:

root@Peanut:/home/donkey# vim &
[1] 3404
root@Peanut:/home/donkey# ps
  PID TTY          TIME CMD
 3373 pts/0    00:00:00 bash
 3404 pts/0    00:00:00 vim That's how it should be
 3405 pts/0    00:00:00 ps

[1]+  Stopped                vim
root@Peanut:/home/donkey# ps
  PID TTY          TIME CMD
 3373 pts/0    00:00:00 bash
 3404 pts/0    00:00:00 vim
 3406 pts/0    00:00:00 ps
root@Peanut:/home/donkey# ps
  PID TTY          TIME CMD
 3373 pts/0    00:00:00 bash
 3404 pts/0    00:00:00 vim
 3407 pts/0    00:00:00 ps
root@Peanut:/home/donkey# kill %1

[1]+  Stopped                vim

The reason is simple, you actually don't run mc, but running bash that run mc.
do the commands :
Code:

export
ls -l `which mc`
strace mc

and post the results here so we can point out why it happened :)

Sarah_Student 10-19-2009 01:01 AM

My output for vim is same as yours.
I think because mc is visual view of shell, first, shell should run and then mc.
Output of the commands you have written is very long.
Should I send it anyway?

itz2000 10-19-2009 04:49 PM

Quote:

Originally Posted by Sarah_Student (Post 3724514)
My output for vim is same as yours.
I think because mc is visual view of shell, first, shell should run and then mc.
Output of the commands you have written is very long.
Should I send it anyway?

yeah why not, so we can learn about this a little more and teach some stuff...


All times are GMT -5. The time now is 06:04 PM.