Is it possible to close a socket with a shell command?

4,662

You can close a socket in sh just like any other file: exec 42>&- where 42 is the file descriptor. What you can't do (except in a few shells that provide an extension for it) is open a socket. But of course that closes the socket in the shell, not in another process.

Closing a socket in a running process would disrupt its behavior in a way that the author of the program is not supposed to expect — it's like going in and modifying a piece of memory. Still, it can be done by connecting to the process with a debugger and making it execute a socket closing API call (that would be the close or shutdown system call on unix).

Share:
4,662

Related videos on Youtube

Abdul
Author by

Abdul

Updated on September 17, 2022

Comments

  • Abdul
    Abdul almost 2 years

    Assume, we have two arrays,

     array1 = [1,2,3,6,3,5,2,5,2,4,3]
     array2 = [3,4,5]
    

    How can I find the value "3" which resides inside array2 and then compare the same from array1 Any help is appreciated.

    Thanks.

    • Tro
      Tro almost 11 years
      Please demonstrate some attempt at solving the problem yourself.
    • Abdul
      Abdul almost 11 years
      I have a set of checkboxes inside a ul li. While onchange the checbox, I getting all the check boxes id and store in a temp var., and also get the current checkbox value in another var. Now, I need to compare and remove the one which i selected currently, say for example.: I having some values in array1 as "1,0:2,0,3,0,4,0", next I clicking the checkbox "3,0", now the array1 looks like "1,0:2,0:3,0:4,0:3,0", but i need it as "1,0:2,0:4,0", where "3,0" is removed.
  • Jason Axelson
    Jason Axelson almost 12 years
    Just a note: it seems that bash can open TCP ports. catonmat.net/blog/tcp-port-scanner-in-bash Also as a sidenote, zsh doesn't support /dev/tcp
  • Lars Ebert
    Lars Ebert almost 11 years
    What exactly do you need? Do you need to know which elements are in both arrays or how often the values of array2 appear in array1? What are you expecting as output?
  • Alexander Gonchiy
    Alexander Gonchiy over 6 years
    Could you please elaborate on the "disruption" part?