Sponsored Content
Top Forums Shell Programming and Scripting Script to kill a process running at a certain port Post 302906715 by MadeInGermany on Monday 23rd of June 2014 07:13:17 AM
Old 06-23-2014
This is a start
Code:
port=14001
port_to_pid(){
netstat -lpn | awk '$0~":"p"\\>" {x=$NF; sub(/^[^0-9]*/,"",x); sub(/[^0-9]*$/,"",x); print x; exit}' p="$1"
}

case $1 in
start)
  pid=`port_to_pid $port`
  if [ -n "$pid" ]; then
    echo "already running, pid=$pid"
  else
    ...
  fi
;;
stop)
  pid=`port_to_pid $port`
  if [ -n "$pid" ]; then
    kill "$pid"
  fi
;;
restart) $0 stop; sleep 1; $0 start
;;
esac

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to kill process while keeping the submitted job running

:confused: I have a process which was schedule to run from 8am - 6pm daily. The scripts will search & run the commands that i was predefined in the database. Ususally, there were about 6-7 jobs for each submission and each job takes about 1-2 hrs and running one by one. And, I have a cron job... (3 Replies)
Discussion started by: hk_newbie
3 Replies

2. UNIX for Advanced & Expert Users

finding a process running on a port

how do I find the process that is running on a port in HP-Unix? Murali (8 Replies)
Discussion started by: manduva
8 Replies

3. UNIX for Dummies Questions & Answers

See if process is running and kill it

I need a simple line to run from apple remote desktop's Unix terminal on multiple different machines to see if Microsoft Entourage is running and kill it.. I imagine this could be done with a ps auxwww and grab the second field, (PID) put it into a variable and do a kill $variable using awk, but... (5 Replies)
Discussion started by: glev2005
5 Replies

4. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

5. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

6. Solaris

Process running on which port

Hi I would like to know, how to find that particular process is running on which port other than /etc/services as this file shows well known ports information. (1 Reply)
Discussion started by: amity
1 Replies

7. AIX

Process running on which port

I would like to know, how to find that particular process is running on which port other than /etc/services as this file shows well known ports information Double post, continued here. If you want answers for different OS, post in a general section instead. If you want your other post moved... (0 Replies)
Discussion started by: amity
0 Replies

8. Shell Programming and Scripting

Help with kill a specific process after certain running time

Hi, Do anybody experience to write a bash script in order to kill a specific process (java) after certain time of running? eg. java java.jar task_run.txt I will run a java program (java.jar) which will run a long list of process (task_run.txt) one by one. I plan to terminate the java... (5 Replies)
Discussion started by: perl_beginner
5 Replies

9. Shell Programming and Scripting

Command to know all the Current running process and how to kill

All, 1.What is the unix comand used for all current running process (Including All current running processes Parent ->child->subchild process) 2.If child and subchild processes are running then what is the unix command to kill parent and its all child subchild processes in UNIX. Kindly... (7 Replies)
Discussion started by: skp
7 Replies

10. UNIX for Beginners Questions & Answers

Idle command to kill the process running n unx box machine

Hi Team , I have one process named as cec_analysiseool that is running on unix box machine now i want to kill this process so please advise what will be the ideal command to kill this , what i have tried is :confused: kill -9 `ps -ef | grep cec_analysiseool | grep -v grep | awk '{print $2}'` (2 Replies)
Discussion started by: unclesamm
2 Replies
rad_detach_pid(3)					     Library Functions Manual						 rad_detach_pid(3)

NAME
rad_detach_pid - Detach a process from a Resource Affinity Domain by pid (libnuma library) SYNOPSIS
#include <numa.h> int rad_detach_pid( pid_t pid ); PARAMETERS
Specifies a process identifier (pid) to detach from a RAD set. DESCRIPTION
The rad_detach_pid() function frees a process that has been bound or attached to a RAD through the functions rad_bind_pid() or rad_attach_pid(), respectively. If the pid argument is NULL, the call is self-directed. That is, the function behaves as if the calling process's pid were specified. Calling rad_detach_pid() for a process that is not attached or bound is not considered to be an error. RETURN VALUES
Success. In this case, rad_detach_pid() detaches the pid specified by pid from the RAD set. Failure. In this case, errno is set to indi- cate the error. ERRORS
If the rad_detach_pid() function fails, errno is set to one of the following values for the reasons specified. The process specified in pid does not exist. The real or effective user ID of the caller does not match the real or effective user ID of the process pid, or the caller does not have appropriate privileges to free processes from RADs. SEE ALSO
Functions: rad_attach_pid(3), rad_bind_pid(3) rad_detach_pid(3)
All times are GMT -4. The time now is 10:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy