Operating System - HP-UX
1824297 Members
4772 Online
109669 Solutions
New Discussion юеВ

Where is the process id of a command

 
Kunal Panchal
New Member

Where is the process id of a command

I have started like 5 instances of 'dd' command,
as below :
for count in 1 2 3 4 5 ; do \
dd if=/dev/urandom of=/dev/null & ;
done

Now, I know with '&' is runs in background and
I can see the pids of each dd process. But can anyone please help me with the location of a file
where HP-UX stores these pids (eg: /var/run/*.pid
Am using HP-UX 11.31 [March 2010 Fusion]
9 REPLIES 9
Prasanth V Aravind
Trusted Contributor

Re: Where is the process id of a command

run command "jobs" - to know the status of background processes.

"ps -ef | grep -i dd" to get pid details.

Gudluck
Prasanth

Kunal Panchal
New Member

Re: Where is the process id of a command

Hi Prasanth,
Thank you for the response, I actually need the location of a file where HPUX would store the pid of my 'dd' processes.
For example, sshd:
# ps -aef | grep -i sshd | grep -vE 'pts|grep'
root 1191 1 0 16:40:05 ? 0:01 /opt/ssh/sbin/sshd

# Now for the file, i would do :
# cat /var/run/sshd.pid
1191

So just wanted to know the location of
such a file, as there is no /procs for HPUX.
Thanks.
singh sanjeev
Trusted Contributor

Re: Where is the process id of a command

i doubt whether any process file may have created with it...


you have given the example of sshd ....but when this script start...script hold syntax to hold the information of process id in a file..
Sanjeev Singh
Prasanth V Aravind
Trusted Contributor

Re: Where is the process id of a command

Hi Kunal,

I don't think, hpux create process id files for dd command.

I had seen these ".pid" files only for daemons & services. The daemons usually checks these pid files, when the start-up/shutdown scripts get called. i feel they also acts as lock-files the services.


But here, dd is a normal command. which not going to create any ".pid" files.

Gudlcuk
Prasanth

Matti_Kurkela
Honored Contributor

Re: Where is the process id of a command

HP-UX does not create .pid files for any process. Instead, many daemons like sshd are programmed to create one for themselves.

The "dd" command does not create a .pid file for itself, because it was not originally designed to run as a daemon.

But your script can create the PID files with a small modification:

for count in 1 2 3 4 5; do \
dd if=/dev/urandom of=/dev/null &; \
echo $! > /tmp/dd_process_$i.pid; \
done

Now it should create files like /tmp/dd_process_1.pid, /tmp/dd_process_2.pid etc. Each of them will contain the PID number of the respective dd process.

In general terms:
The special shell variable $! will always contain the PID of the last process you ran in the background with "&" (within the same shell session). If you haven't used "&" in your current session, $! will be an empty string.

MK
MK
Kunal Panchal
New Member

Re: Where is the process id of a command

Perfect Matti...!!!

I was thinking on the same lines and just happened to write the below code :

proc_count=0
until [ $proc_count -eq 10 ]
do
echo -e "Starting Instance : $proc_count"
/usr/bin/dd if=/dev/urandom of=/dev/null &
for proc in $(ps -aef | grep -iE '\/usr\/bin\/dd' | awk '{print $2}')
do
echo $proc > /var/run/dd_inst_"$proc_count".pid
done
sleep 3
(( proc_count += 1 ))
done

once that script is ran, the pid files are generated in /var/run/

[root@slpam13] # ls /var/run/ | grep -i dd
dd_inst_0.pid
dd_inst_1.pid
dd_inst_2.pid
dd_inst_3.pid
dd_inst_4.pid
dd_inst_5.pid
dd_inst_6.pid
dd_inst_7.pid
dd_inst_8.pid
dd_inst_9.pid

What do you think of that..!!!!
singh sanjeev
Trusted Contributor

Re: Where is the process id of a command

Perfect !!!!....
Sanjeev Singh
Kunal Panchal
New Member

Re: Where is the process id of a command

Done assigning the points..!!!

@ Sanjeev, Prasanth - Thank you guys for taking time off and replying.
@Matti - Thanks a ton for the suggestion...!!!

Closing the thread.-:)
Kunal Panchal
New Member

Re: Where is the process id of a command

Thanks again :-)