Halt grunt server from terminal - terminal

I've installed and am exploring Yeoman but one thing that I can't seem to find an answer to is, how do I halt the grunt server from running?
Is this something that can be done from the terminal? It just sits and waits.

You can stop it with ctrl + c in terminal
If it's a task that is running in background you can find his process
id (pid) with ps aux | grep grunt and then kill it with kill {pid}

Related

kill doesn't actually terminate the ghost process

In order to terminate the ghost process (process which hasn't terminated properly and hence it still pending to be killed)
I used the
kill -9 <process-id>
At times it works perfectly, and when I check the process after killing it, it is gone
ps -aux | grep python
However, surprisingly, now I am able to see the ghost process even after the kill command. What's the problem?
In the image above, I tried to kill the process with id 23756 but it still appears in ps aux
Referring to my answer to previous question of Visual Studio ghost process
VSCode kill running processes
Looks like, I had to close the debug process that was still incomplete. Basically, killing the application or closing the debug or something on those lines, helps you to terminate the ghost process.

How do I handle stopping my service?

I've turned a program I wrote into a service, and I have a bash script that runs to start up the actual program, since there are things that have to be started in a particular order. The contents of the startup script (called with start-stop-daemon from the init.d script look like :
./rfid_reader &
sleep 2
java ReaderClass &
This works fine, but how do I go about killing them when it comes time to stop the process?
I've seen pidfiles used, do I just get the PIDs of the two programs, write them to a file, and then kill them when it comes time to shut them down, or do I have to ps -ef | grep program to get their PIDs?
I don't think killall is a good idea to do this. You'd better to record the PID of the program started in background in some file(e.g. PID_FILE) and then kill $(<$PID_FILE) to stop it.
Please refer to this thread for how to get the PID the previous started background program.
Assuming you know the name of your program, you can kill them as below :
killall -KILL program_name

How to hide/quit terminal while program is still running in OS X?

I'm doing my project and I need to log keystrokes system wide in macOS. So, I turned over to GitHub and found Swift-Keylogger. The only problem is I can't quit the Terminal while the program is still running.
Is there any way to not to run this in terminal or closing the terminal window instead of creating a mac app like here.
Note: There are some mac app style executables in github but they are not providing the output I want and some need additional permissions.
Instead of running the executable like ./Keylogger use nohup ./Keylogger &.
You can quit the Terminal after executing the command.
To kill the Keylogger, run ps -e | grep "Keylogger" to get pid and kill -9 pid.
P.S. I thought of adding it as well as running at startup but I'm too lazy to update the repository.

Grunt task that restarts my app via command line

I'm looking for a Grunt task that would restart my Sails app. Currently, the only way I know how to restart a Sails app is going to the terminal where the app is running and enter 'Ctrl + C'. Then 'Sails lift' to start it up again. Is there a way that Grunt can run these two commands for me?
I got close using this: https://github.com/sindresorhus/grunt-shell, but couldn't quite take it home. Any advice?
EDIT:
The following successfully kill the Sails app via the command line, but the Grunt task (below) still causes an error when I try to start the Sails app:
pkill -2 node /usr/local/bin/sails and pkill -SIGINT node /usr/local/bin/sails
The code in my Grunt task is:
module.exports = function(grunt) {
grunt.config.set('shell', {
multiple: {
command: [
'pkill -SIGINT node /usr/local/bin/sails',
'sails lift'
].join('&&')
}
});
grunt.loadNpmTasks('grunt-shell');
};
(I'm using this Grunt task: https://github.com/sindresorhus/grunt-shell)
And when I try to start the app ("Sails lift") I get a "Command failed" error. I think it has to do with the fact that I'm trying to kill the app with the app itself. Or something.
pkill can be used to kill a process based on its name instead of PID
pkill -SIGINT {name of process} && Sails lift
This should do what you need. You can find the name of the process pretty easily by doing a top or a ps aux | grep "sail"
Im sure the process is just sails, so it would likely be:
pkill -SIGINT sails && Sails lift
Ctrl + C sends SIGINT (see signal(7)), so if you can use shell commands, use the kill command like this:
kill -SIGINT {pid-of-your-Sails-app} && Sails lift
I've been using nodemon for this task and it works great:
https://github.com/remy/nodemon

How can I find out what a command is executing in Terminal on MacOs

After I run a shell script (which call a bunch a other scripts depend on conditions. which is too complicated to understand), I can execute a command 'gdbclient' at my MacOS terminal.
But when I do 'which gdbclient' and 'alias gdbclient', it shows nothing.
Is there anyway for me to find out what 'gdbclient' is actually doing?
You can open up another terminal window and type: ps
That will list all the running processes.
If your script is running as a different user than the current one, you can use ps -ef to list all running processes.
If you know the PID of the process that ran your script, you can find all child processes via parent PID using ps -f | grep [pid]
You can use the Activity Monitor to check things out pretty thoroughly. To get the right privileges to see everything going on you can do:
sudo open /Applications/Utilities/Activity\ Monitor.app/
Dtrace can give you some helpful information: dtrace
to find process 'gdbclient':
ps aux | grep gdbclient
That wont tell you what it's "doing" but that it's running

Resources