sindresorhus / fkill-cli

Fabulously kill processes. Cross-platform.
MIT License
6.88k stars 159 forks source link

Search by port #19

Closed JakubKahovec closed 6 years ago

JakubKahovec commented 7 years ago

It'd be great if it's possible to also search by a port being open by a process

sindresorhus commented 7 years ago

I like the idea. How do you imagine it would work? What would it look like?

JakubKahovec commented 7 years ago

Thanks ;-) It might be something like you run fkill-cli and next to the Running processes there'd be in brackets by what you're searching and you can switch it by a shortcut.

Search running processes (by Name/Pid/Port) :

SamVerschueren commented 7 years ago

I see two options

Flags

fkill -p or fkill --port could start the tool in port mode where searching will match the port.

Automatic parsing

Just run fkill and if the input looks like a port (numeric, between 0 and 65535, ...) use the port is filter strategy.

sindresorhus commented 7 years ago

I think automatic parsing would be nicer, but one downside (?) is that you would miss the ability browse through ports. Not sure that's something people would need though.

SamVerschueren commented 7 years ago

What do you mean with browse through ports?

sindresorhus commented 7 years ago

@SamVerschueren I mean, if you just want to see what apps are using which ports.

dnbkr commented 7 years ago

You could use automatic parsing for finding and killing (when you know the port number connected to the proc you want to kill) and then also have a 'ports' subcommand, maybe?

fkill 8080
# searches for procs using port 8080, the same what automatic searching currently works (maybe, if there's a proc owning the port it jumps to the top of the search, and proc names / args containing the port by coincidence come below it)

fkill ports
# displays scrollable list of procs using ports, with the ports in their own column along side pids 

Sidenote; https://www.npmjs.com/package/node-netstat may be good for this.

pirate commented 7 years ago

Careful, people will assume the first arg to fkill is a PID or process name, not a port, and they can conflict. Probably better to have fkill --port 8080 or fkill ports then search with port:8080 or something like that.

You can find all port-> process mappings with netstat -tan or lsof +c 0 -i:8080.

dnbkr commented 7 years ago

@sindresorhus, @pirate how do you feel about:

fkill ports  # interactive autocomplete search based on port number
fkill ports 8080  # kill the process currently using port 8080
fkill ports 8080 8081 8082  # kill the processes currently using ports 8080-2

using a ports subcommand will limit any confusion between port number and pid.

pirate commented 7 years ago

I'd rather a flag than a subcommand, as the word ports itself could be a process name, and that leads to ambiguity with parsing the first argument. How about --port?

dnbkr commented 7 years ago

yep, that makes sense - --port works for me.

fkill --port  # interactive autocomplete search based on port number
fkill 8080 --port  # kill the process currently using port 8080
fkill -p 8080 8081 8082  # kill the processes currently using ports 8080-2
pirate commented 7 years ago

👍 for your second example, I think only allowing fkill --port 8080 makes more sense, (otherwise you run into the pid vs port ambiguity problem).

dnbkr commented 7 years ago

do you mean fkill --port 8080 vs fkill 8080 --port ? Because i think flags should be treated as non-positional; so if -p or --port is present then positional arg 1-n will always be treated as ports, not pids.

pirate commented 7 years ago

Up to you, I personally favor stricter argument parsing, but it's your call @sindresorhus & @coffeedoughnuts ;)

sindresorhus commented 7 years ago

do you mean fkill --port 8080 vs fkill 8080 --port ?

The argument parser we use supports both, but we should only document fkill 8080 --port as it's the clearest. In fkill --port 8080 it could both mean it's the value of --port or the first argument.

sindresorhus commented 7 years ago

I'm ok with a --port flag.

YurySolovyov commented 7 years ago

how about searching by port after user typed colon : ? $ fkill user types: :8080 shows list of apps on 8080

pirate commented 7 years ago

I like it.

On Tue, Apr 4, 2017 at 2:35 PM Yury notifications@github.com wrote:

how about searching by port after user typed colon : ? $ fkill user types: :8080 shows list of apps on 8080

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sindresorhus/fkill-cli/issues/19#issuecomment-291592332, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfOCwhpjLZx6_QDQKhJqNEp5IdJUHF0ks5rso1WgaJpZM4MThKz .

-- --From Nick (Mobile)

sindresorhus commented 7 years ago

Yeah, I would be fine with that too.

I assume it would be:

$ fkill :8080

And

$ fkill
? Running processes: :8080

Is everyone good with this?

// @SamVerschueren @coffeedoughnuts @MarkTiedemann @AlexTes

MarkTiedemann commented 7 years ago

LGTM.

dnbkr commented 7 years ago

Yep, :PORT seems good to me;

sindresorhus commented 7 years ago

Cool. Let's go with that then. Pull request welcome :)

sindresorhus commented 6 years ago

Marking as "help wanted" again. See https://github.com/sindresorhus/fkill-cli/pull/27 for previous attempt.