LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 02-25-2013, 08:31 PM   #1
fantasy1215
Member
 
Registered: Oct 2011
Posts: 70

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


Code:
static sem_t s_threadsem;
int main(void)
{
	//initialize resources
	#define NONE_PROCESS_SHARE 0
	const unsigned int THREADCNT = 2;
	if( 0 != sem_init(&s_threadsem, NONE_PROCESS_SHARE, THREADCNT) )
	{
		cout<<"sem_init fail" <<endl;
		exit(-1);
	}
	
	
	while(1)
	{
		dowork();
		sleep(2);
	}
	
	//destroy resources
	sem_destroy(&s_threadsem);
	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
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,645

Rep: Reputation: 1250Reputation: 1250Reputation: 1250Reputation: 1250Reputation: 1250Reputation: 1250Reputation: 1250Reputation: 1250Reputation: 1250
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
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,727

Rep: Reputation: 488Reputation: 488Reputation: 488Reputation: 488Reputation: 488
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)
 
  


Reply


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 arun5002 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


All times are GMT -5. The time now is 11:24 AM.

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