Killproc and pidofproc on linux

I have a script that uses killproc and procofpid commands and works fine on 64 bit utilization. But when I ran the script on 32-bit redhat, I found that the above commands are missing.

I do not have 32-bit Suse and 64-bit Redhat machines to test my script.

I believe that on the 64-bit redhat the above commands should be available? Or is it the above commands specific to Suse and redhat?

thanks

+7
linux shell process kill
source share
6 answers

Teams are unlikely to be portable. This is actually the first time I hear about them, but I think your problem is to work with the process by name, not pid.

Check out man pgrep or man pkill - they are a bit more portable. They are part of the procps package (where ps and top come from) and should be available on all Linux variants. They are also available on Solaris.

+4
source share

killproc is in redhat enterprise linux 5.4 as part of /etc/init.d/functions

if you need it just

./etc/init.d/functions

in your script to load shell functions, possibly in other versions of redhat, but this is the only one I need to pass at the moment

+8
source share

These commands are defined as part of the Linux Standard Base (LSB), as @AndreKR notes.

However, on some systems, such as Redhat (and possibly SUSE), depending on the installed packages, these functions may not be detected at the location indicated by LSB, which is equal to /lib/lsb/init-functions . Rather, they are defined within /etc/init.d/functions . In addition, in some versions of the Redhat variant /etc/init.d/functions no LSB function start_daemon function. If you add the following snippet at the top of your script, it should be portable for most distributions / installations:

 if [[ -f /lib/lsb/init-functions ]]; then . /lib/lsb/init-functions elif [[ -f /etc/init.d/functions ]]; then . /etc/init.d/functions # Pretend to be LSB-compliant function start_daemon() { daemon $* } else echo "Linux LSB init function script or Redhat /etc/init.d/functions is required for this script." echo "See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html" exit 1 fi 
+6
source share

The ones used by Ubuntu are part of the Standard Linux Base specification and are documented there .

+2
source share

I think these commands are distribution features: I have never seen them. killproc should be some kind of kill, but what should procofpid do?

In the header, you are talking about pidofproc, you can find this command under pidof in most linux boxes.

0
source share

I had the same problem as yours, it issued a warning:

pidof: Invalid command line options!

I changed

 "killproc -d 10 $cmd" 

to

 "kill -9 \`pidof $cmd\`" 
-one
source share

All Articles