LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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: 75

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
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
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: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
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



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:58 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration