Why does the 'pid' keep changing every time?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why does the 'pid' keep changing every time?
# 1  
Old 12-30-2009
Network Why does the 'pid' keep changing every time?

HI

I checked the pid of a process on my machine using this command.

Code:
ps -ef | awk '/process_name/{ print $2 }'

I get the result as 12245
I check it again after 2 mins, I get the result as 12264
I check it again after 2 mins, I get the result as 12289
It keeps on this. How does this pid work?

And, I also have another question. By using the pid, Can I know which process it belongs to?
# 2  
Old 12-30-2009
Code:
ps -ef | grep pid#


Last edited by Yogesh Sawant; 12-31-2009 at 01:56 PM.. Reason: added code tags
# 3  
Old 12-30-2009
I suspect that if you temporarily replace $2 by $0 you will find that the awk statement is in fact selecting its own pid.
Try putting square brackets around one of the characters of the process name you are looking for, e.g.:
Code:
ps -ef | awk '/[l]s/{ print $2 }'


Last edited by Scrutinizer; 12-30-2009 at 12:31 PM..
# 4  
Old 12-30-2009
Belt and braces approach in case there is more than one hit.

Code:
ps -ef|grep 'process_name'|grep -v "grep"|awk '{print $2}'|while read PID
do
      echo "PID=${PID}"
done


Ps. Scrutinizer is right, you were getting PID of the awk.

The answer to your supplementary is:
Code:
ps -fp${PID}

# 5  
Old 12-30-2009
Quote:
Originally Posted by ss3944
How does this pid work?
The process id (PID) is an integer assigned by the operating system at process creation time that uniquely identifies that process. On most operating systems, it's simply an incrementing counter; on OpenBSD, PID generation is randomized. Two processes cannot share a PID, but PID values may be reused. The PID does not change during the lifetime of a process. A different PID is a different process.

Quote:
Originally Posted by ss3944
By using the pid, Can I know which process it belongs to?
If you know the PID, you can use ps to find the process info.

Code:
ps -p PID

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Kill nohup process with changing PID

Hi there! I have a tricky problem concerning a nohup process: I started a python2.7 script which loops over a function. At the end it restarts the function. Due to a mistake I'm now having a never ending nohup process that I have to kill. I started the program execution with: >>nohup... (4 Replies)
Discussion started by: Lydia
4 Replies

2. Red Hat

Touch - changing date and time

Hi, I am facing a problem with the command - TOUCH on Linux. See the example below: File on Linux: rw-rw-r-- user1 user1 Jan 01 09:00 test.txt The file - test.txt was created by the user - user1. Now, I want to change the date and time, but using other user - user2 The user2... (12 Replies)
Discussion started by: brjohnsmith
12 Replies

3. Shell Programming and Scripting

Changing time-stamp with sed

Hi ! I try to change a time-stamp hh:mm:ss allways to full ten-minutes. example: 12:51:03 to 12:50:03 sed 's/::/:{0-5}0:/g' file.txt but it will not work propperly, because the minute-decade will be replaced with the bracket-term {0-5}. Can someone please give me a hint? Thanks in... (6 Replies)
Discussion started by: IMPe
6 Replies

4. UNIX for Dummies Questions & Answers

Start Time and period of a PID

Hi, Below is my OS details. uname -an SunOS mymachine 5.10 Generic_144488-07 sun4v sparc SUNW,SPARC-Enterprise-T5220 I need to know when was my Apache server last started. Whats is the best and most reliable way to find out not just for Apache but for any PID per say? I am... (16 Replies)
Discussion started by: mohtashims
16 Replies

5. AIX

changing the time zone in aix

hi may aix version is 6100-06-03-1048 when i give date command it shows the time zone as root@cbspsgui01 #date Fri Sep 16 08:43:42 Africa/Johannesburg 2011 I want to change the time zone to GMT +02:00: After i change the time zone it should show something like the one below when i type... (2 Replies)
Discussion started by: newtoaixos
2 Replies

6. HP-UX

Changing system time in HP-UX using perl

Hi All, I would like to change system time for my testing purposes. All I need is to change the system time forward/backward in seconds. I am providing the perl code that I am using to change system time on all platforms. --------- use strict; use English; my $sec; my $mday; my... (2 Replies)
Discussion started by: xyz3245
2 Replies

7. AIX

changing server time

Hi all, we have IBM- AIX 5.2 operating system on that we have our oracle production database and there is daily crontab script for backup. my boss told me to change the server time.if i change the server time by root user does it give problem to any application or script which are... (2 Replies)
Discussion started by: younusdba
2 Replies

8. Shell Programming and Scripting

Changing the output in own time display's.

Hi all, I've written a script which collects some information and sendsout a mail.. (code pasted below) ssh -l ora${sid} ${primaryhost} "tail -50 /oracle/$ORACLE_SID/newbackup/END_BACKUP.log" |grep 'insert' |tail -1| awk '{print $7}' >> ${RESULTFILE} Output would look like this:... (1 Reply)
Discussion started by: suri.tyson
1 Replies

9. Shell Programming and Scripting

changing modified time

How to change the modified time of a file to any specified time. ls -ltr drwxr-xr-x 2 pipe pipe 4096 Jun 10 10:33 coredump_06062008 ---------------------------------------------------------------------- here file coredump_06062008 last modified time is Jun 10 10:33 and i... (1 Reply)
Discussion started by: ali560045
1 Replies

10. UNIX for Dummies Questions & Answers

How to MV without changing Time Stamp

Hi, I need to move the set of files, and it should be same time stamp as previous. How to do this? (3 Replies)
Discussion started by: redlotus72
3 Replies
Login or Register to Ask a Question