killproc not working on my daemon, returns 7.

Hello everyone,

I’m running SLES10SP3/OES2SP2.

I need to be able to get
/sbin/killproc -TERM /root/Desktop/mydaemond
to work, but it is not. This command causes nothing to be logged to /var/log/messages with the syslog() function written inside mydaemond for SIGTERM messages, and mydaemond does not terminate.

However, correctly, if I do “kill <pid of mydaemond>”, then this SIGTERM action is logged to /var/log/messages with the syslog() inside mydaemond, AND mydaemond terminates.

When I run /etc/rc.d/mydaemon start,
mydaemond starts up fine.

But, I am not able to stop mydaemond with killproc.
When I run /etc/rc.d/mydaemon stop,
mydaemond does not stop.

mydaemond is still listed as running in the output of
ps ax | grep mydaemond

If I run
/sbin/killproc -TERM /root/Desktop/mydaemond
echo $?

Then, 7 is displayed and mydaemond is still running.

7 returned for killproc = “Program was not running to receive the specified signal.”

See: 8:killproc - Linux Man Pages Manual Documentation for Linux / Solaris / UNIX / BSD

Note: The contents of /var/run/mydaemond.pid is not the correct PID as shown in ps ax | grep mydaemond, probably because of the necessary fork()ing done in mydaemond.
However, killproc is supposed to only need the full path to my executable (/root/Desktop/mydaemond) and not the PID number. Further, these SuSE /etc/rc.d/skeleton based scripts are supposed to work with daemons that should all have fork() in them at least once. Mine does fork()ing twice per the “Advanced Programming in the UNIX Environment, 2nd Edition” book.

Help please.

Thanks!

Joe

First of all, you may not get help from here for SLES/SLED becausue this is openSUSE forum.

Are you sure that the running program is /root/Desktop/mydaemond ?

I have posted where I think the mostly like place is that I will get an answer that leads to a “good” solution for this problem.

Yes, see below:

Note: “mydaemon” <==> “makehome”

oes2:~/Desktop # ps ax | grep makehome
27624 pts/0 R+ 0:00 grep makehome
oes2:~/Desktop #
oes2:~/Desktop # /etc/rc.d/makehome start
Starting makehome done
oes2:~/Desktop # ps ax | grep makehome
27828 ? S 0:00 /root/Desktop/makehomed
27833 pts/0 S+ 0:00 grep makehome
oes2:~/Desktop # /etc/rc.d/makehome stop
Shutting down makehome done
oes2:~/Desktop # ps ax | grep makehome
27828 ? S 0:00 /root/Desktop/makehomed
27869 pts/0 R+ 0:00 grep makehome
oes2:~/Desktop # /etc/rc.d/makehome status
Checking for service makehome running
oes2:~/Desktop #

First of all, if you are writing your own launch script, it’s possible to write the actual pid into the file with the judicious use of exec. Second, can the program be located via /proc, as the man page says? If not, then it will fail to find the process.

Thanks. I can do that, but since I am fork()ing in the daemon, I will have to write the correct pid to the lock file (/var/run/makehomed.pid) from the child process and not the launch script.

I guess this also implies that the /etc/rc.d/skeleton code is not correct.

Yes, it is there (/proc/<correct pid>/cmdline).

Thanks.

Is the full path in there? Also /proc/<pid>/exe has to be a symlink to the actual file, according to the man page you quoted.

Incidentally *.pid is not a lock file. It’s just a file containing the pid. It could be used as a lock file, but lock files normally go into /var/lock whereas pid files go into /var/run

Yes.

lrwxrwxrwx 1 root root 0 Mar 9 10:34 exe -> /root/Desktop/makehomed

Hmmm… Thanks for this. I’ll have to look back through the books and see if/where I may have gotten this crossed-up.

If any other thoughts, please pass them along. I will run down any path that may bear fruit.


Hi
Two things may be causing problems, one using the Desktop area for
coding (This can cause all sorts of funny results), second being in the
root environment (GUI?)?

Try /root directory, better to develop as a user, test using su -c all
as your user…


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.27.45-0.1-default
up 22:00, 3 users, load average: 0.03, 0.05, 0.02
GPU GeForce 8600 GTS Silent - CUDA Driver Version: 190.53

Thanks, Malcolm and Ken.

I’m downloading openSUSE 11.2 now. Will try this again tonight on that OS and see what gives, if anything.


Is your process ignoring SIGTERM?


When I do this:

“kill -s SIGTERM 16556”

This shows up in /var/log/messages from calling syslog() within makehomed:

“Mar 9 16:35:50 oes2 /var/run/makehomed.pid: got SIGTERM; exiting”

When I do
ps ax | grep makehome

makehomed is indeed gone.


I tried killproc with the -t option (KILL) and that didn’t help either. i.e., killproc did not cause makehomed to terminate.


killproc is not finding your process then. Use the -v option to show more details.

I reckon -v is broke too.


oes2:~ # ps ax | grep makehomed
26446 ? S 0:00 /root/Desktop/makehomed
27413 pts/3 R+ 0:00 grep makehomed
oes2:~ # killproc -v /root/Desktop/makehomed
oes2:~ # ps ax | grep makehomed
26446 ? S 0:00 /root/Desktop/makehomed
27630 pts/3 R+ 0:00 grep makehomed
oes2:~ #

# /bin/sleep 60 &
[1] 18920
# killproc -v /bin/sleep
SIGTERM sleep(18920)
[1] Terminated              /bin/sleep 60
# killproc -v /bin/ls
#

Looks like it outputs nothing if it cannot find the process. Maybe strace killproc to see what it’s doing then.

Thanks Ken,

Haven’t used strace before. Will try to do that tomorrow.
It’s midnight here. Got to get up early tomorrow.

NOTE: I just tested the binary makehomed and script /etc/rc.d/makehome on openSUSE 11.2, and they work fine.

See below.

HOWEVER, there are differences I made with chmod on /root/makehomed and on /etc/rc.d/makehome, and makehomed is located in /root/ on openSUSE and in /root/Desktop/ on SLES10/OES2. Need to make those differences zero and see if that changes anything.


opensuse-64bit:/etc/rc.d # ps ax | grep makehome
7955 pts/0 S+ 0:00 grep makehome

opensuse-64bit:/etc/rc.d # ./makehome start
Starting makehome done

opensuse-64bit:/etc/rc.d # ps ax | grep makehome
7979 ? S 0:00 /root/makehomed
7981 pts/0 R+ 0:00 grep makehome

opensuse-64bit:/etc/rc.d # ./makehome stop
Shutting down makehome done

opensuse-64bit:/etc/rc.d # ps ax | grep makehome
7991 pts/0 R+ 0:00 grep makehome

opensuse-64bit:/etc/rc.d #

Arghhhhh…

Same here:


oes2:~ # /bin/sleep 60 &
[1] 16325
oes2:~ # killproc -v /bin/sleep
SIGTERM sleep(16325)
[1]+ Terminated /bin/sleep 60
oes2:~ # killproc -v /bin/ls
oes2:~ #

Strace killproc on your daemon.

OK, here it is:

http://www.nofreewill.com/cEl2cGLoec3/strace-makehome-sles10.txt


Well, I don’t know what has happened but it’s working now on SLES10.

I did a “strace killproc -v /root/Desktop/makehomed” and it worked. Not only that, but “/etc/rc.d/makehome stop” seems to be working now too.


Obviously you have a very smart killproc program that can detect when questions are being asked about it in forums.opensuse.org. I suggest you maintain its connection to the Internet so that you can continue to provide it with encouragement to behave properly. lol!