Tag Info

Hot answers tagged

22

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 ...


20

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


11

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.


11

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 ...


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

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 ...


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.


7

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


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

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: ...


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 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

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


3

use env: 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


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

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


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

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 ...


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

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


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

The process ID is off by one because you have put an extra & after the $javaCommandLine. In other words, you have put two processes in the background before calling echo $!, thus getting the PID of >>$serviceLogFile 2>&1 rather than $javaCommandLine. Those two pieces should be put in one, as the old 2 line codes shows su ...


3

No, it hopefully doesn't terminate the process.


3

Did you try either: ps -p <PID> -o cmd or if you only want the command name ps -p <PID> -o comm Or try this one: cat /proc/<PID>/cmdname



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