Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-25-2013, 08:31 PM   #1
Registered: Oct 2011
Posts: 75

Rep: Reputation: Disabled
what does kill -9 and killall -9 do and don't?

static sem_t s_threadsem;
int main(void)
	//initialize resources
	const unsigned int THREADCNT = 2;
	if( 0 != sem_init(&s_threadsem, NONE_PROCESS_SHARE, THREADCNT) )
		cout<<"sem_init fail" <<endl;
	//destroy resources
	return 0;
The code above do a infinite loop (like a server), If I use kill -9 or killall -9 to kill this process, Will the linux operating system reclaim the sem_t resource correctly? And what else kind resources would linux operating system not reclaim correctly(that we should take care)?
I wonder what mechanism do you guru use to stop and restart your process while not using kill -9?
Thanks in advance!
Old 02-26-2013, 03:23 AM   #2
LQ Guru
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,873

Rep: Reputation: 4481Reputation: 4481Reputation: 4481Reputation: 4481Reputation: 4481Reputation: 4481Reputation: 4481Reputation: 4481Reputation: 4481Reputation: 4481Reputation: 4481
kill -9 will not allow to cleanup, so you should not use it. You should implement your own signal handler (sigint, siguser1, whatever) to stop your server and properly clean up.
Old 02-26-2013, 04:57 AM   #3
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,014

Rep: Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444
I don't know what happens with posix semaphores when the process ends; SystemV semaphores on the other hand can be used with option SEM_UNDO, meaning: undo the changes when the process terminates (see man 2 semop)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Could not able kill apache log using killall -9 httpd command jsaravana87 Linux - Server 1 06-19-2012 01:24 AM
Using killall to kill mysql processes? SirTristan Linux - Newbie 3 08-14-2009 03:25 PM
when a process cann't be terminated through kill/skill/pkill/killall... Osirix Linux - Software 9 07-18-2006 11:16 PM
kill/killall not working (?) didi156 Linux - Software 2 05-20-2004 11:47 PM
kill vs. killall, AIX vs. Linux thebeaglebeagle Linux - Newbie 1 09-24-2003 02:41 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration