Tag Info

Hot answers tagged

25

By default, you can only write to /var/run as a user with an effective user ID of 0 (ie as root). This is for good reasons, so whatever you do, don't go and change the permissions of /var/run... Instead, as root, create a directory under /var/run: # mkdir /var/run/mydaemon Then change its ownership to the user/group under which you wish to run your ...


24

any_command args & my_child_PID=$! IOW, just like $$ holds your PID, $! has the PID of the most recently executed background command.


15

Add the --make-pidfile option to your call of start-stop-daemon. --pidfile only tells start-stop-daemon where to look for the pidfile, without --make-pidfile it is assume that this pidfile is created by the program to be launched, and not by start-stop-daemon. Be sure to read the manpage of start-stop-daemon(8) for more details.


14

Try pkill: pkill -STOP -P the_ppid If you don't have pkill, there's an alternative: ps -o pid --ppid the_ppid --no-heading | xargs kill -STOP


13

That directory is ephemeral by design. If its contents stuck around across boots, all sorts of ugly effects could occur, as control scripts of various sorts look in there to see what processes they should be signaling. On recent system, this temporary nature is enforced by mounting /var/run as tmpfs, while older systems just deleted everything in the ...


12

What can be simpler than echo $!? As one line: myCommand & echo $!


12

You have two chances at least: change your init script to do a mkdir -p /var/run/sphinx/ or set pid_file = /var/run/sphinx-searchd.pid in /etc/sphinx.conf I'm for the second one.


10

in simple terms, no: a process (e.g. a daemon) can crash and not have the time to clear its .pid file. A technique to be more certain of the state of a program: use an explicit communication channel such as a socket. Write the socket port in a file and have the supervisor process look it up. You can also use the services of DBus on Linux: register a ...


10

You've had, and accepted, a Linux answer. On Solaris, the maximum value of a process ID is a kernel tunable parameter — pidmax in /etc/system — that defaults to 30,000 and that can be set anywhere between 266 and 999,999. Note that this is not max_nprocs, which is a kernel tunable parameter with a subtly different function.


9

From http://www.alexxoid.com/blog/linux/getting-the-max-pid-value-for-linux-process.html: To get the max PID value that can be assigned to Linux process, run the following command: cat /proc/sys/kernel/pid_max On most Linux machines, the result is 32768 (= 215). However, it can be set to any value up to 4194304 (= 222) if necessary. Servers might ...


7

You can use env to modify the environment: start-stop-daemon --start --pidfile /var/run/wine-app.pid -m -c myuser -g mygroup -k 002 --exec /usr/bin/env VAR1="Value" /home/myuser/.wine/drive_c/Program\ Files/wine-app.exe


7

Unlike pidof, pgrep can be given a variety of options to restrict which processes it returns PIDs for. One that may be particularly useful is to select based on PPID using the PID of the current process. pgrep -P $$ imapsync which will only output PIDs of imapsync if they are children of your script.


6

You'll usually find the PID files for daemonized processes in /var/run/ on Redhat/CentOS-style systems. Short of that, you can always look in the process init script. For instance, the SSH daemon is started with the script in /etc/init.d/sshd. Sometimes the PID will be defined there (search for pid, PID, PIDFILE, PID_FILE, etc.). However, most other ...


5

I would recommend enabling Apache mod_status and turn ExtendedStatus On. Slicehost has an excellent article on how to accomplish this (I would use the "elinks" package vs. "lynx" but that is a personal preference). When you view the Apache server-status URL, there will be a PID, VHost and Request columns - they should go a long way towards pinpointing the ...


4

One way of getting the process's binary location is to use lsof and grep for the first txt segment. For example, in the shell to see what binary the shell is, use the shell's PID in place of $$. $ lsof -p $$ | grep txt bash 78228 blair txt REG 14,2 1244928 6568359 /bin/bash bash 78228 blair txt REG 14,2 1059792 23699809 ...


4

Wrap the command in a small script #!/bin/bash yourcommand & echo $! >/path/to/pid.file


4

I do not know of any simpler solution, but isn't using $! good enough? You can always assign the value to some other variable if you need it later, as said by others. As a side note, instead of piping from ps you could use pgrep or pidof.


4

I assume you're basing your conclusions on this line of your pmap output: total kB 601248 49456 39620 If so, you're reading it wrong. Those numbers are the total number of kilobytes in use, not bytes, so your JVM has asked for about 600MB of memory, of which 49MB is actually stored in physical memory (the rest is swapped out, or committed ...


4

I just found this in the changelog for the psacct RPM: * Fri Nov 13 2009 Ivana Varekova <varekova(at)redhat.com> - 6.3.2-56 - fix the psacct to deal with all acct types and if it is possible and wanted then add the possibility to display the pid and ppid number So it looks like it depends in exactly which release you are using.


4

lsof -i $PROTCOL:$PORT fuser $PORT/$PROTOCOL nestat -np | grep $PORT Any of those should work. Below is sample output showing my mail client using ephemeral port 56375 to talk to an IMAP server. $ sudo netstat -np | grep 56375 tcp 0 0 192.168.1.1:56375 217.70.184.11:993 ESTABLISHED 3256/thunderbird $ fuser 56375/tcp 56375/tcp: ...


3

You can try this. Create a directory /var/run/test/ and then change the permission of this directory to the same user as your program runs. " chown /var/run/test/" . Now in your application change the location of the PID file to /var/run/test/test.pid. This should get things working for you.


3

Although people are pointing out specific services (e.g. the "Web Deployment Agent Service"), this fails to address the root cause. If you just disable services that trigger the problem, chances are it will rear its head again in the future in a marginally different guise. So it's worth understanding what's going wrong, because that leads to a better fix. ...


3

Culprit was Web Deployment Agent Service. Better solution than net stop http is to stop the services named "Web Deployment Agent Service".


3

It's most likely IIS 6.0 or later. The HTTP protocol stack (HTTP.sys), which runs in kernel mode, receives client requests and routes them to the appropriate request queue. Worker processes, which run in user mode, pull the requests directly from their own kernel request queues, eliminating the process hops that occur in IIS 5.0 (and that also occur in ...


3

Example: you're after the associate process command name for PID 45109... > % ps awx | awk '$1 == 45109 { print $5 }' > /Applications/Safari.app/Contents/MacOS/Safari


3

Found it! It's in: /var/run/apache2.pid


3

It sends it to where stdout is pointed to for this process. An easier way is to use jstack, which is provided by the JDK. With this tool, you can simply do: jstack <pid> > thread-dump.out Make sure you do this as the user the process is running as. What a thread dump is, is a snapshot representation of where all current threads within that Java ...


3

You can do what you want with this code: echo $$ > /var/log/script.pid && exec /usr/bin/script exec replaces the current process with another - which means that it retains the current pid. If you want your parent script to carry on you can wrap that: bash -c 'echo $$ && exec /usr/bin/script' That will run the subcommand in a new ...


3

for most linux distros enumerating the /proc/{pid} is a good way to obtain information about the running processes, and usually how the userspace commands like "ps" are communicating with the kernel. So for example you can do; [ -d "/proc/${kpid}" ] && echo "process exists" || echo "process not exists"


3

If you have the AIX toolboox for linux apps, you could use lsof it should help, something like: host:/:$ lsof -i :22 sshd 1953 root 3u IPv4 300864051 0t0 TCP *:ssh (LISTEN) sshd 1953 root 4u IPv6 300864053 0t0 TCP *:ssh (LISTEN) sshd 19753 root 3u IPv4 366276287 0t0 TCP ...



Only top voted, non community-wiki answers of a minimum length are eligible