Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Console Foundations Processes Killing Processes

Confused as to how to terminate a program

I'm confused as to how to terminate programs in bash.
From my understanding, Ctrl + c (command + c for macs) sends the term (terminate) signal to the process directly; it tells the process to please terminate. This allows the program to perform clean-up operations and exit smoothly. You can only seem to run this command from w/n the process....so if you are not running the process yourself, or it is running in another bash instance, you cannot use this command to terminate a process.
However, kill PID# seems to send the same (term) signal....is this the same as Ctrl + c (command + c for macs), but is used when you are outside of the process or the process is open in another bash instance?
Also, am i understanding correctly that the kill command sends the signal to the operating system kernel, which shuts down the process instead of sending the signal to the process itself?
I also read that the kill command actually sends the term signal, so does kill -TERM PID# do the same thing as kill PID#?
kill -KILL PID to me seems to be the syntax to send the kill signal to the OS kernel directly....
Would greatly appreciate if someone could clear this up for me!

Mathew Kurian
Mathew Kurian
4,698 Points

I also have this question.

2 Answers

ywang04
ywang04
6,762 Points

However, kill PID# seems to send the same (term) signal....is this the same as Ctrl + c (command + c for macs), but is used when you are outside of the process or the process is open in another bash instance?

Yes, ctrl + c means send the term signal to the current process.

Also, am i understanding correctly that the kill command sends the signal to the operating system kernel, which shuts down the process instead of sending the signal to the process itself?

kill command sends the signal to the process that you want to kill.

I also read that the kill command actually sends the term signal, so does kill -TERM PID# do the same thing as kill PID#?

Yes
faraz
PLUS
faraz
Courses Plus Student 21,474 Points

From the man page (man kill):

"The default signal for kill is TERM."

So yes, you are right, kill PID is equivalent to hitting CTRL + Z from within the program -- so it is used "when you are outside of the process or the process is open in another bash instance."

Hope this helps!