LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Process ID changing ubruptly while killing mysqld (https://www.linuxquestions.org/questions/linux-newbie-8/process-id-changing-ubruptly-while-killing-mysqld-827918/)

vinaytp 08-23-2010 12:54 AM

Process ID changing ubruptly while killing mysqld
 
Hi All,

I tried to stop mysqld deamon. It failed
Code:

[zabbix@CDCTGIMCLSA ~]$ sudo /etc/init.d/mysqld stop
Stopping MySQL:                                            [FAILED]

Then I tried to kill the process, but Process Id is getting changed ubruptly.

Code:

[zabbix@CDCTGIMCLSA ~]$ ps -e | grep mysql
 5954 pts/1    00:00:00 mysqld
27338 pts/1    00:00:01 mysqld_safe
[zabbix@CDCTGIMCLSA ~]$ sudo kill -9 5954
kill 5954: No such process
[zabbix@CDCTGIMCLSA ~]$ ps -e | grep mysql
 6155 pts/1    00:00:00 mysqld
27338 pts/1    00:00:02 mysqld_safe
[zabbix@CDCTGIMCLSA ~]$ sudo kill -9 6155
kill 6155: No such process
[zabbix@CDCTGIMCLSA ~]$ ps -e | grep mysql
 6315 pts/1    00:00:00 mysqld
27338 pts/1    00:00:02 mysqld_safe

But following works !!
Code:

sudo kill -9 `pgrep mysqld`
Any reason for this ubrupt changing pid ?

chrism01 08-23-2010 01:08 AM

Check if mysqld_safe is the parent

Code:

ps -ef|grep mysql
I don't have Linux system in front of me to check right now.

vinaytp 08-23-2010 01:19 AM

Thanks for your reply chrism01.

Here mysqld seems to be the parent as mysqld PID 17705 < mysqld_safe PID 23163

Code:

[308718@CDCTGIMCLSB ~]$ sudo /sbin/service mysqld stop
Stopping MySQL:                                            [FAILED]
[308718@CDCTGIMCLSB ~]$ ps -e | grep mysql
17705 ?        00:00:00 mysqld
23163 ?        00:00:06 mysqld_safe


sem007 08-23-2010 02:20 AM

Quote:

Check if mysqld_safe is the parent
chrism01 is right

run pstree | grep mysql and you will find parent and child process

Code:

debian:~# pstree | grep mysql
    |-mysqld_safe-+-logger
    |            `-mysqld---27*[{mysqld}]

if single instant running on server you can user pkill command

Code:

# ps -e | grep mysql
  2837 ?        00:00:00 mysqld_safe
  2874 ?        00:00:11 mysqld
# pkill -15 mysqld
# pkill -15 mysqld_safe
# ps -e | grep mysql

HTH

vinaytp 08-23-2010 02:49 AM

Thanks sem007,

Here mysqld_safe seems to be the parenet with pstree command

Code:

[zabbix@CDCTGIMCLSA ~]$ sudo pstree | grep mysq
    |-mysqld_safe---mysqld---9*[{mysqld}]

But is it Okay to kill a process with pkill or Kill, when the deamon can't be stopped with

Code:

/etc/init.d/mysqld stop

Kenny_Strawn 08-23-2010 02:52 AM

Here's a thought:

Code:

killall /etc/init.d/mysqld

sem007 08-23-2010 02:59 AM

just run pkill command to kill mysqld

Code:

[root@localhost ~]# ps aux | grep mysql
root      1711  0.0  0.1  4492  1104 pts/3    S    21:46  0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --user=mysql
mysql    1767  0.1  1.6 137188 17048 pts/3    Sl  21:46  0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock
root      1798  0.0  0.0  3920  660 pts/3    R+  21:48  0:00 grep mysql


[root@localhost ~]# pkill -9 mysqld


[root@localhost ~]# ps aux | grep mysql
root      1802  0.0  0.0  3920  656 pts/3    S+  21:48  0:00 grep mysql

[root@localhost ~]#

@ Kenny_Strawn

Quote:


Code:

killall /etc/init.d/mysqld

it gives me error

Code:

[root@localhost ~]# ps -e | grep mysql
 1849 pts/3    00:00:00 mysqld_safe
 1909 pts/3    00:00:00 mysqld

[root@localhost ~]# killall /etc/init.d/mysqld
/etc/init.d/mysqld: no process killed

[root@localhost ~]#


[EDIT]

when i run below command it works

killall mysqld

vinaytp 08-23-2010 03:04 AM

@sem007,

Yeah I got it how this pkill works. But my question is, does killing a process with pkill or kill cause abrupt deamon stop ?

Is it the step taken when the deamon fails to stop ?

@ Kenny_Strawn

This gives error..
Code:

[root@localhost ~]# killall /etc/init.d/mysqld
/etc/init.d/mysqld: no process killed
[root@localhost ~]#


sem007 08-23-2010 03:10 AM

Quote:

Yeah I got it how this pkill works. But my question is, does killing a process with pkill or kill cause abrupt deamon stop ?

Is it the step taken when the deamon fails to stop ?
when you stop service it will use kill command to terminate process.

some lines from /etc/init.d/mysqld script
Code:

stop(){
        MYSQLPID=`cat "$mypidfile"  2>/dev/null `
        if [ -n "$MYSQLPID" ]; then
            /bin/kill "$MYSQLPID" >/dev/null 2>&1

I advise use signal 15 (TERM) when you kill process.

HTH

quanta 08-23-2010 03:30 AM

You should use ps -ef (full format) instead of ps -e. I'm pretty sure you will recognize that: mysqld_safe is parent process of mysqld:
Code:

# ps -ef | grep mysqld
root      2657    1  0 Jun13 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --user=mysql
mysql    2707  2657  0 Jun13 ?        03:19:36 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock


chrism01 08-23-2010 03:49 AM

Exactly, the relative values of the pids is irrelevant, the system pids wrap around after 4 digits...

vinaytp 08-23-2010 04:22 AM

@quanta, @chrism01, @sem007
Thank you for your advices.


All times are GMT -5. The time now is 12:03 AM.