Kill a Program in Linux

I came across a really simple problem while using my Linux OS. I am used to the CTRL+ALT+DEL in Windows to open the Task Manager to close programs. I wasn’t sure how to do the same in a Linux environment.

To close a program in Linux from the command line, there are two options:

If you don’t know the name of the application, you can use this one. It will prompt you to click on the window of the application you are trying to close.
After clicking on it, the program will immediately close.

$ sudo xkill

If you know the name of the application, you can type:
$ sudo killall <name of application>
For example: $ sudo killall firefox


Creating Cron Job on RHEL7

Found a great resource for creating cron jobs in Red Hat Enterprise Linux 7:

(Yes it is from the creator’s website!) How cron jobs are laid out in /etc/crontab:

# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * username  command to be executed

So for example, if you want to create a cron job that will start XAMPP Apache server every weekday:

0 8 * * mon,tue,wed,thu,fri root /opt/lampp/laampp start

If you aren’t sure if you have cron or anacron available on your machine, you can run:

$ rpm -q cronie cronie-anacron

If you have cron packages installed, the command above will list them.

Passing a PHP Array through AJAX

If you are creating dynamic elements on your page, you will need to be able to send information to and from the browser. There’s lots of documentation on how to POST data using AJAX to the server side. What if you want to return an array of data back to the browser?

    url: "<?php echo site_url('test/urlGoesHere/'); ?>",
    type: 'POST',
    data: form_data,
    success: function(data) {

Marking the dataType as json here is key.

In your PHP file, use json_encode to send your array:

print json_encode($my_array);

If you don’t want to save the array into a variable, you can also just write the array between the json_encode parantheses:

print json_encode(array("name"=>$name,"title"=>"Ms."));

Then in your AJAX success, you can access the array elements this way:[0]; //the first name element
data.title;  // "Ms."

If this was your array: array("Jack", "Mr."), then your AJAX data can be handled like this:

    url: "",
    type: 'POST',
    data: form_data,
    success: function(data) {
        var name = data[0];
        var title = data[1];
        alert('Name: ' + name + ', Title: ' + title);

Looping Through JavaScript Associative Array

Create your array so that it follows the following format:

var weekdays = {"MON" : "monday", "TUES" : "tuesday", "WED": "wednesday", "THURS" : "thursday", "FRI" : "friday"};

*Note the use of curly braces instead of square brackets and also the colon instead of =>

Then to loop through this associative array:

for (var day in weekdays) {
  document.write( day + " : " + weekdays[day] + "<br />" );

Here, the variable ‘day’ represents each individual key in the array ‘weekdays’. The loop will run through each key and stop after the last one is completed.

Your output:

KEY : value

MON : monday
TUES : tuesday
WED : wednesday
THURS : thursday
FRI: friday