0

QUESTION: What does each element of the command:

pkill -INT -f '^php test_program.php$'

do when I run it in the linux terminal? I already know that the command kills the process called test_program.php, but I don't know what all the different elements of the command are doing. Please explain in as simple terminology as possible! I am new to linux commands and I prefer baby lingo to tech lingo at the moment :)


MY RESEARCH: By running man pkill in the linux terminal, a manual appears with the following pkill definition:

  • signal processs based on their name or other attributes.

which leads me to believe that pkill doesn't only kill a process, but rather can send a lot of different signals, one of which might kill the process. The structure/synopsis of the pkill command was displayed as: pkill [option] pattern

From the list of options in the same manual, -f, -full had the following definition:

  • The pattern is normally only matched against the process name. When -f is set, the full command line is used.

I didn't completely understand what that meant. Also, there is a -INT before the -f in the command, so that leads me to believe that more than one option can be joined together, however -INT was not displayed in the manual.

The other parts of the command seem to be identifying the program that is running: '^php test_program.php$', but why isn't that part of the command just 'test_program.php'? What does ^php at the beginning and $ and the end do?

Webeng
  • 7,050
  • 4
  • 31
  • 59

1 Answers1

0

You are looking at a Regular Expression. This expression looks for the string test_program.php anywhere in the process name. So if the process name would be something like

/var/php -runcommand test_program.php

it would find the process and kill it.

This also explains the -f, -full option. Not using a Regular Expression, you would have to take the full process name (the preceeding line) to match the process.

Finally, the -INT is usually used to send a runlevel to the task.

EDIT

I was wrong, the -INT option is not used for runlevels (which are for the Linux kernel) but to send signals to a task. This could be something like Term (terminate), Stop (shut down) or Cont (continue process). pkill sends by default the terminate signal to the process.

The /var/php -runcommand test_program.php was an example for a process. If you use the command ps ax, you get a list of all processes and which programs execute them. So I just assumed that the php interpreter resides in /var/php/ and the execution of the php file is a command.

tobi6
  • 8,033
  • 6
  • 26
  • 41
  • I'm a bit new to the commands being used. I'm not quite sure what a runlevel is, also i'm not even sure what `/var/php -runcommand test_program.php` is doing, probably just running the program as I did with `php test_program.php`? And which part of the whole command is killing the process? because the definition of `pkill` was to signal commands, so if there are many commands, which one of the ones in the command line specified the "killing"? – Webeng May 25 '16 at 07:23