<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: pkill not working as expected in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561806#M487461</link>
    <description>&lt;P&gt;&amp;gt;The example: demonstrates the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But that was not the example for your issue.&amp;nbsp; That was the example for the OP to see what he was getting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;pgrep does not discriminate the basename of a process when pathnames such as /usr/bin/sh or ./bin/sh are used:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes it can.&amp;nbsp; If you look at my fine print and pgrep(1), your sh example would be:&lt;/P&gt;&lt;P&gt;ps -f -p$(pgrep '^sh$' | tr "^J" ",")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Basically, if I have a command I have never used before, I like to read the whole man page. :-)&lt;/P&gt;</description>
    <pubDate>Fri, 01 Aug 2014 19:15:24 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2014-08-01T19:15:24Z</dc:date>
    <item>
      <title>pkill not working as expected</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6558736#M487450</link>
      <description>&lt;P&gt;I am trying to use pkill to kill a process that contains bea.home within the command line. I only need the default SIGTERM. The command is: "pkill -u oracle -f bea.home". The pgrep command "pgrep -u oracle -f bea.home" works and shows the process id.&amp;nbsp; When I run the pkill command the process is not killed and I get a return code of 1 (process not found). Is this a bug? I can kill the process in other ways using a ps, awk and xargs but pkill looked like a better method if&amp;nbsp;it would only work. From what I can see pkill is new to HPUX and first appears in 11.31.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. This thread has been moved&amp;nbsp;from General to HP-UX &amp;gt; System Admin. - Hp forum Moderator&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2014 02:55:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6558736#M487450</guid>
      <dc:creator>ITLOUIS</dc:creator>
      <dc:date>2014-07-31T02:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: pkill not working as expected</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6560146#M487452</link>
      <description>&lt;P&gt;&amp;gt;"pgrep -u oracle -f bea.home" works and shows the process id.&amp;nbsp; When I run the pkill command the process is not killed&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you sure that process didn't just die?&lt;/P&gt;&lt;P&gt;What does "kill -0 pid-from-pgrep" show for that PID?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2014 09:09:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6560146#M487452</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2014-07-31T09:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: pkill not working as expected</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561074#M487457</link>
      <description>&lt;P&gt;pgrep and pkil suffer from similar issues associated with ps | grep. I am really surprised that all the effort to create these commands did not include the exact process name (which ps does have). The -C option in ps is the only reliable way to select a program by name. Rather than use grep (which matches indiscriminately), the -C option looks at the process table name for an exact match. However -C (and also useful, -H and -o) is only valid when the environment variable UNIX95 is defined. The value is unimportant (can be null), it just must exist. But don't set the variable globally. UNIX95 affects other processes. Instead, define the variable just for the ps process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the typical ps|grep and the exact match ps -C results while searching for all "sh" processes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;# ps -ef|grep sh
root        37     0  0  Jul  8  ?        00:00:00 nfs_global_flush
root        62     0  0  Jul  8  ?        00:00:00 shutdowndaemon
root         4     0  0  Jul  8  ?        00:00:27 unhashdaemon
root        86     0  0  Jul  8  ?        00:00:00 str_mblk_flush_daemon
root      3809     1  0  Jul  8  ?        00:00:00 /opt/ssh/sbin/sshd
root     10488 10486  0 20:12:18 pts/2    00:00:00 sh
root     10418  3809  0 20:11:59 ?        00:00:00 sshd: root@pts/2
root     10494  6360  0 20:12:24 pts/0    00:00:00 grep sh
root      6357  3809  0 18:44:37 ?        00:00:00 sshd: root@pts/0
root     10121 10118  0 20:05:07 pts/1    00:00:00 -sh
root     10486 10421  0 20:12:10 pts/2    00:00:00 csh
root      6360  6357  0 18:44:39 pts/0    00:00:00 -sh
root     10421 10418  0 20:12:00 pts/2    00:00:00 -sh
blh      10320 10121  0 20:11:01 pts/1    00:00:00 -sh
root     10118  3809  0 20:05:06 ?        00:00:00 sshd: root@pts/1
blh      10382 10320  0 20:11:08 pts/1    00:00:00 ksh

# UNIX95=1 ps -f -C sh
UID        PID  PPID  C    STIME TTY          TIME CMD
root     10488 10486  0 20:12:18 pts/2    00:00:00 sh
root     10121 10118  0 20:05:07 pts/1    00:00:00 -sh
root      6360  6357  0 18:44:39 pts/0    00:00:00 -sh
root     10421 10418  0 20:12:00 pts/2    00:00:00 -sh
blh      10320 10121  0 20:11:01 pts/1    00:00:00 -sh&lt;/PRE&gt;&lt;P&gt;As you can see, grep matches lots of "sh" parts of each process line -- and that's very bad, especially when you need to kill specific processes by name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another thing I see a lot is grep used to find processes when ps already has an exact match option:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;grep pid - not needed, use ps -p&lt;/P&gt;&lt;P&gt;grep uid - not needed, use ps -u&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can look for multiple pid or uid values - just use commas as in:&amp;nbsp; ps -u sybase,oracle&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your example, you can find the processes by exact name match and then grep for the command line strings.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Aug 2014 00:41:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561074#M487457</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2014-08-01T00:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: pkill not working as expected</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561380#M487458</link>
      <description>&lt;P&gt;&amp;gt;pgrep and pkill suffer from similar issues associated with ps | grep.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not hardly, they have the flexibility to do either.&amp;nbsp; It is the user that intentionally used -f to match anywhere in the command line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;did not include the exact process name (which ps does have).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You just have to understand EREs, regexp(5):&lt;/P&gt;&lt;P&gt;pgrep "^init$" to just find init.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to see what pgrep finds:&lt;/P&gt;&lt;P&gt;$ ps -f -p $(pgrep init | tr "^J" ",")&lt;BR /&gt;UID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PID&amp;nbsp; PPID&amp;nbsp; C&amp;nbsp;&amp;nbsp;&amp;nbsp; STIME TTY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TIME CMD&lt;BR /&gt;root&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 61&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; Apr&amp;nbsp; 8&amp;nbsp; ?&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 00:00:00 mdep_initiator_thread&lt;BR /&gt;root&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 65&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; Apr&amp;nbsp; 8&amp;nbsp; ?&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 00:00:00 pagetable_init_daemon&lt;BR /&gt;root&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; Apr&amp;nbsp; 8&amp;nbsp; ?&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 00:00:06 init&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;(That ^J is formed by Control-V then Control-J or ENTER.)&lt;/P&gt;</description>
      <pubDate>Fri, 01 Aug 2014 19:05:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561380#M487458</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2014-08-01T19:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: pkill not working as expected</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561538#M487460</link>
      <description>&lt;P&gt;The example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$ ps -f -p $(pgrep init | tr "^J" ",")
UID        PID  PPID  C    STIME TTY          TIME CMD
root        61     0  0  Apr  8  ?        00:00:00 mdep_initiator_thread
root        65     0  0  Apr  8  ?        00:00:00 pagetable_init_daemon
root         1     0  0  Apr  8  ?        00:00:06 init&lt;/PRE&gt;&lt;P&gt;demonstrates the problem. The result is no different than ps -ef | grep init -- unwanted processes are found.&lt;BR /&gt;egrep does not disciminate the basename of a process when pathnames such as /usr/bin/sh or ./bin/sh are used:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;# ps -f -p$(pgrep sh | tr "^J" ",")&lt;BR /&gt;UID        PID  PPID  C    STIME TTY          TIME CMD
root        62     0  0  Jul  8  ?        00:00:00 shutdowndaemon
root         4     0  0  Jul  8  ?        00:00:27 unhashdaemon
root        86     0  0  Jul  8  ?        00:00:00 str_mblk_flush_daemon
root      3809     1  0  Jul  8  ?        00:00:00 /opt/ssh/sbin/sshd
root     16388 16323  0 08:48:01 pts/1    00:00:00 sh
root     16617 16391  0 08:52:48 pts/1    00:00:00 /usr/bin/sh
root     16252  3809  0 08:47:45 ?        00:00:00 sshd: root@pts/0
root     16320  3809  0 08:47:55 ?        00:00:00 sshd: root@pts/1&lt;BR /&gt;blh&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 17379 17317&amp;nbsp; 0 09:03:48 pts/1&amp;nbsp;&amp;nbsp;&amp;nbsp; 00:00:00 ./bin/sh&lt;BR /&gt;root     16389 16388  0 08:48:01 pts/1    00:00:00 sh
root     16390 16389  0 08:48:04 pts/1    00:00:00 ksh
root     16391 16390  0 08:48:05 pts/1    00:00:00 sh
root     16255 16252  0 08:47:46 pts/0    00:00:00 -sh
root     16323 16320  0 08:47:56 pts/1    00:00:00 -sh
&lt;BR /&gt;# UNIX95=1 ps -f -C sh
UID        PID  PPID  C    STIME TTY          TIME CMD
root     16388 16323  0 08:48:01 pts/1    00:00:00 sh
root     16617 16391  0 08:52:48 pts/1    00:00:00 /usr/bin/sh
root     16389 16388  0 08:48:01 pts/1    00:00:00 sh
root     16391 16390  0 08:48:05 pts/1    00:00:00 sh
root     16255 16252  0 08:47:46 pts/0    00:00:00 -sh
root     16323 16320  0 08:47:56 pts/1    00:00:00 -sh&lt;BR /&gt;blh&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 17379 17317&amp;nbsp; 0 09:03:48 pts/1&amp;nbsp;&amp;nbsp;&amp;nbsp; 00:00:00 ./bin/sh&lt;/PRE&gt;&lt;P&gt;So the first example finds unwanted process names that are not "sh".&lt;/P&gt;&lt;P&gt;This is the problem solved by ps -C &amp;lt;process_name&amp;gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Aug 2014 13:07:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561538#M487460</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2014-08-01T13:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: pkill not working as expected</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561806#M487461</link>
      <description>&lt;P&gt;&amp;gt;The example: demonstrates the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But that was not the example for your issue.&amp;nbsp; That was the example for the OP to see what he was getting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;pgrep does not discriminate the basename of a process when pathnames such as /usr/bin/sh or ./bin/sh are used:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes it can.&amp;nbsp; If you look at my fine print and pgrep(1), your sh example would be:&lt;/P&gt;&lt;P&gt;ps -f -p$(pgrep '^sh$' | tr "^J" ",")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Basically, if I have a command I have never used before, I like to read the whole man page. :-)&lt;/P&gt;</description>
      <pubDate>Fri, 01 Aug 2014 19:15:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561806#M487461</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2014-08-01T19:15:24Z</dc:date>
    </item>
    <item>
      <title>Re: pkill not working as expected</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561936#M487462</link>
      <description>&lt;P&gt;&amp;gt;&amp;gt; If you look at my fine print and pgrep(1), your sh example would be:&lt;BR /&gt;&amp;gt;&amp;gt; ps -f -p$(pgrep '^sh$' | tr "^J" ",")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Correct indeed. Both constructs give the same results:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ps -f -p$(pgrep '^sh$' | tr "^J" ",")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;UNIX95=1 ps -f -C sh&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which illustrates the Unix adage:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "If you can't find at least 5 ways to do the same thing, you haven't looked hard enough"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The pgrep man page gives a slight hint with the telnet$ example, but would be much enhanced with the RE '^telnet$' or similar example. Personally, I find the -C concept simpler to use and explain, and only one process is needed rather than 3.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Aug 2014 01:21:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561936#M487462</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2014-08-02T01:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: pkill not working as expected</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561968#M487464</link>
      <description>&lt;P&gt;&amp;gt;I find the -C concept simpler to use and explain, and only one process is needed rather than 3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, that example was only to show the OP what he was getting with pgrep -f, not that I would ever use it. :-)&lt;/P&gt;&lt;P&gt;And yes, I normally use ps -H -C many times a day and never used pgrep(1) before.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Aug 2014 06:12:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pkill-not-working-as-expected/m-p/6561968#M487464</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2014-08-02T06:12:11Z</dc:date>
    </item>
  </channel>
</rss>

