pid

Bash script to kill and restart Hudson

I am a novice at Bash scripting but I'm a quick learner. Usually. I'm trying to write a script to kill and restart an instance of Hudson--it needs to be restarted to pick up changes in environment variables. What I have so far: #!/bin/bash h=`pgrep -f hudson` if test "$h" != ""; then kill $h while [ "$h" != "" ]; do sleep 1 ...

How to find PID of an dash-exec command

NOTE: I thought I was using bash, but /bin/sh is linked to /bin/dash, which has this weird exec problem. I have a simple bash shell script on Linux which is used to launch a server process (which I did not write or control) and would like to have the bash shell script output the launched process's PID to a pidfile. The problem is that ...

How to use the pidfile library correctly?

I already read the man page of the pidfile function family. But I don't really understand it. What is the correct usage? Is there a more elaborate example available? I think I understand pidfile_open. But when should I call pidfile_write and prdfile_close? From which process? Parent or child? What parameters do I have to pass to those fu...

Alternative to /proc/PID/exe symlink for retrieving another processes full path via PID

I'm looking for a alternative method to reading the /proc/PID/exe symbolic link in which to obtain the full path of a process in Android/Linux. The reason being is that on Android, /proc/PID/exe for any process other than your own or 'self' seem to have restricted (permission denied) access. I have looked into the following as well - ...

Linux / Bash using PS -f for specific PID returns in different format than PS -f, also queston about using Grep to parse this

I have a need, for a python script I'm creating, to first get just the PID of a process (based on its name) and then to get from that process, usings its PID, its time duration, which, from the printout below, would be "00:00:00" root 5686 1 0 Sep23 ? 00:00:00 process-name I am using this to get just the PID, by the p...

Stop cron job from starting while it's already running (even across servers)

I don't think this is an exact duplicate of other questions, but feel free to point me somewhere if it's already been answered. I'm looking for a way to have a cron job only start running if it isn't already running. For example, if a job runs every 15 minutes but occasionally takes an hour to run, I don't want duplicate processes to st...

Redirecting standard output to a file containing the pid of the logging process

I've searched for a while but i can't either find an answer or come up with a solution of my own, so I turn to you guys. First question I actually ask here :) I would like to run several instances of the same program, and redirect each of these programs' standard output to a file that contains that same process' pid, something like: my...

get process id in Makefile

How can I get the pid of my make command in the Makefile? Specifically, I want to use a temp directory that will be unique to this build. I tried: TEMPDIR = /tmp/myprog.$$$$ but this seems to store TEMPDIR as "/tmp/myprog.$$" and then eval as a new pid for every command which refs this! How do I get one pid for all of them (I'd prefe...

Grepping for Python processes

I'm running a script that executes either: ./ide.py # or python ./ide.py After that I use pstree -p | grep ide.py to check, but I only found a Python process. If I have many Python scripts running, how can I distinguish them from each other? ...

In python is there a cross-platform way of determining what process is listening to a given port?

In linux, I can use lsof -i as in the following function: def FindProcessUsingPort(portnum): import os fp = os.popen("lsof -i :%s" % portnum) lines = fp.readlines() fp.close() pid = None if len(lines) >= 2: pid = int(lines[1].split()[1]) return pid Is there a cross-platform way to figure this out? ...

Scaling PID (Proportional Integral Derivative) Output

I have implemented a PID function using the formula, correction = Kp * error + Kd * (error - prevError) + kI * (sum of errors) What should I do to keep my output between a certain range? say 0-255 If I disregard any value not between 0 to 255 it produces a jiggly behavior? ...

How to interchange data between two python applications?

I have two python applications. I need to send commands and data between them (between two processes). What is the best way to do that? One program is a daemon who should accept commands and parameters from another GUI application. How can I make daemon to monitor comands from GUI, while making it's job? I prefer solution would be cros...

Are unix process ID's base 10?

After reading a series of man pages and searching through google, I decided to post this question to the bright folks of stack overflow. I'm working on a basic Unix Shell and one of the requirements is that I have to implement a command to echo out the shell's pid in base 10 ASCII... Before I read this requirement, I had assumed that pr...

Storing pid file for a daemon run as user

Is there a preffered place to store a pid file for a daemon that's run as a user? /var/run is the standard place, but this is for a user daemon so it doesnt have write privelages there. Presumably my daemon will be started from .profile or .bashrc or something. Is just saving it to /tmp a bad idea? ...

Java: Get a process given a pid

Say I have a current running process known, how can I turn this into a Process object in Java? The process is already running, so I don't want to spawn off another one, I just want to encapsulate it into a Process object that I can use within the java code. Something along the lines of: int pid = getPid(); Process proc = magicGetProcess...

Get PID of COM server

I create a com object in powershell like so: $application = new-object -ComObject "word.application" Is there a way to get the PID (or some other unique identifier) of the launched MS Word instance? I want to check if the program is blocked e.g. by modal dialogs asking for passwords, and I can't do it from whithin PowerShell. Thx! ...