Tag Info

New answers tagged

1

Basically, you can't. Read this article, titled: TASK_KILLABLE: New process state in Linux. excerpt Linux® kernel 2.6.25 introduced a new process state for putting processes to sleep called TASK_KILLABLE, which offers an alternative to the efficient but potentially unkillable TASK_UNINTERRUPTIBLE and the easy-to-awaken but safer TASK_INTERRUPTIBLE. ...


2

Your script does not have /tmp/console_test opened, the cat process does. Your script is reading from a pipe that is connected to the cat process; that's what you're seeing in your question. Search for the cat process and check that one out. You probably want something like this: while read x; do echo "received $x" eval "$x" done < ...


2

Try something like this: (example output from busybox on OpenWrt on one of my routers) root@ap8:~# xargs -0 printf '%s\n' </proc/991/cmdline /usr/sbin/uhttpd -f -h /www -r ap8 -x /cgi-bin -u /ubus -t 60 -T 30 -k 20 -A 1 -n 3 -N 100 -R -p 0.0.0.0:80 -p [::]:80 /proc/$PID/cmdline contains the arguments of process $PID like a C-ish strings one after ...


0

Method #1 - Using ps You could use ps -eaf | grep 1234. Example $ ps -eaf | grep 28865 saml 28865 9661 0 03:06 pts/2 00:00:00 bash -c sleep 10000; while [ 1 ];do echo hi;sleep 10;done saml 28866 28865 0 03:06 pts/2 00:00:00 sleep 10000 NOTE: Busybox's ps doesn't include the -eaf switches as shown above from a typical ps that's included ...


3

You could use the -o switch to specify your output format: $ ps -eo args From the man page: Command with all its arguments as a string. Modifications to the arguments may be shown. [...] You may also use the -p switch to select a specific PID: $ ps -p [PID] -o args pidof may also be used to switch from process name to PID, hence allowing the use ...


-2

To disable Teamviewer on startup : teamviewer --daemon disable


2

This is from the ps manpage: PROCESS STATE CODES: Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will display to describe the state of a process: D uninterruptible sleep (usually IO) R running or runnable (on run queue) S interruptible sleep (waiting for an event to ...


1

Why execution times of the same binary differ on multiple executions The key problem here is the non-deterministic behavior due to the way the CPU works. Modern superscalar CPUs can execute multiple instructions at a time or change the order of commands to be executed (out-of-order execution). Regarding your example, it's also possible that optimization in ...


4

The value can only be extended up to a theoretical maximum of 32768 for 32 bit systems or 4194304 for 64 bit.


2

You could do something like this to start a process with the desired PID. while true; do bash -c '[[ "$$" == 99999 ]] && echo PID is 99999'; done You can wait until you get the desired PID and probably replace the echo statement to whatever you actually need to test. References will the same pid be used after getting killed? EDIT Why the ...


1

Whatever you are trying to do there is most probably the better approach, but if you are determined something like while [[ 1 == 1 ]]; do sleep 10000& done will start many sleeps, but it may take a while to start all of them. When you will have enough processes just hit Ctrl-C to exit while loop.


11

However, are there any other clever tools/methods to see if process listening on TCP port receives a message? You can use strace with -e trace=network. This is what it prints on accepting a TCP connection, receiving an HTTP request, sending an HTTP response and closing the connection: $ strace -v -f -e trace=network -p `cat logs/my_server.pid` Process ...


0

One way to do it is to use top to find the pid of the process using the most CPU. I started a bash CPU hog in one terminal: bash -c "while true; do :; done" Then in another terminal I can kill it as follows: kill $( top -l2 | grep bash | sort -nrk3 | awk '{print $1;exit}' ) Note, since this is osx, this is the BSD top and not the GNU version. -l2 ...


1

Natively, several processes can be run with the same executable code. If this isn't happening naturally then yes, the program itself made it happen. However, I couldn't tell you how this is done on a Windows (or at least, Windows-quite-like) system. On Linux, we mostly use .pid files. Is it because the exe file runs as a server? Well, this could also ...


1

A process is an instance of a program. A program can be instanced several times, that is, several processes can be created with the same executable code loaded. I would like to quote a line from Understanding the Linux Kernel by Daniel P. Bovet and Marco Cesati: It is important to distinguish programs from processes; several processes can execute the ...


2

This is almost certainly implemented by the program itself, and probably impossible for the OS to force for all but the most rudimentary programs. If, however, you know the manner by which the program decides that it is already running, and that manner is something you can influence, then you can indeed get an executable to launch a new process (or not). ...


0

I know you found your own answer, but is there a reason you can't do something like this: (set -x; for f in 1 2 3 4 ; do echo "$f"; sleep $f; done) Perhaps you can't co-mingle the output of the actual job and the output from bash showing the currently executing line. Also, FWIW, if you prefer verbosity, set -o xtrace.


3

Workaround using GNU parallel. parallel --nonall --sshloginfile .cluster --tag w In my case I use a file .cluster, which contains the hostnames where I want to run the command: $ cat .cluster n04 n05 n06 My output n04 11:19:43 up 110 days, 20:54, 2 users, load average: 0.16, 0.24, 0.25 n04 USER TTY FROM LOGIN@ IDLE JCPU ...


1

In general, no. If a program never calls execve, you have no opportunity to intercept anything, unless you manage to write code to preload over a symbol, but I'm not sure that even works with WINE.


5

Since the command is still running in screen, its parent bash has not reread any history so: reattach to screen press ^Z then up arrow bonus: wrap the command in single quotes (navigating with ^A^A - because screen(1) - and ^E) and echo + redirect into a file fg to pursue command execution There are caveats, but this is useful enough, most of the time.


-1

I am missing one bit in the answers that is slightly related to dying parents: when a process writes on a pipe for which there is no reading process anymore, it gets a SIGPIPE. The standard action for SIGPIPE is termination. This can indeed cause processes to die. In fact, it is the standard way in which the program yes dies. If I execute (yes;echo $? ...


33

I knew I was grasping at straws, but UNIX never fails! Here's how I managed it: bash$ gdb --pid 8909 ... Loaded symbols for /lib/i386-linux-gnu/i686/cmov/libnss_files.so.2 0xb76e7424 in __kernel_vsyscall () Then at the (gdb) prompt I ran the command, call write_history("/tmp/foo") which will write this history to the file /tmp/foo. (gdb) call ...


-1

So what above posters are saying is, the children don't die, the parent kills them (or sends them a signal on which they terminate). So you can have what you ask, if you program the Parent to (1) keep a record of all its children, and (2) send a signal to all its children. This is what the Shell does, and it should be what your parent process does. It may ...


8

When a process exits, all its children also die (unless you use NOHUP in which case they get back to init). This is correct if the process is a session leader. When a session leader dies, a SIGHUP is sent to all members of that session. In practice that means its children and their descendants. A process makes itself session leader by calling setsid. ...


59

When a process exits, all its children also die (unless you use NOHUP in which case they get back to init). This is wrong. Dead wrong. That person has been lying to you, either when they said that or when they said they knew something about Unix and processes. There are two ways in which the death of a process can indirectly cause the death of its ...


2

Take a look at this script https://github.com/pixelb/scripts/commits/master/scripts/ps_mem.py which we are using regularly to debug our applications. It is not a simple task and the methods differ from kernel to kernel sometimes. From the description of the script you can read the following. # Try to determine how much RAM is currently being used per ...


1

I figured you can analyze the /proc/ID/maps file for each process in question - if you list all the mapped pages, discard all executable pages, shared pages and pages that are not mapped to an inode. If you then sum up their sizes (which can be computed from the beginning and ending addresses) then the result is the actual memory pressure of the process. I ...


0

Checking at regular intervals is neither convenient nor reliable. If your scripts stop, they won't be restarted until the cron job runs again. There are tools for ensuring that a process is always running, such as supervise from daemontools, monit, god, supervisord, etc. Start the monitoring tool at boot time and leave it alone. while true; do … done is a ...


4

I'd like to expand on Davidann's answer since you are new to the concept of a cron job. Every UNIX or Linux system has a crontab stored somewhere. The crontab is a plain text file. Consider the following: (From the Gentoo Wiki on Cron) #Mins Hours Days Months Day of the week 10 3 1 1 * /bin/echo "I don't really like cron" ...


1

Instead of having a separate cron just to kick it off if it isn't running, why not just use the cron exclusively? E.g.: * * * * * 'lockfile -r 0 /tmp/the.lock; php parse_tweets.php; rm -f /tmp/the.lock' This will run the cron job which will execute parse_tweets.php once per minute using a lockfile so that you will only have one copy run by cron running ...


7

Check the kernel documentation for information about files in /proc. There is one such file per process because not all processes see the same mount points. Chroot is a traditional Unix feature that makes it possible to restrict processes to a subtree of the filesystem tree. A chrooted process would not see mount points outside its root. Linux takes this ...


2

If you know the listening port of the process, you can use fuser with -k flag. Something like, fuser -k 3002/tcp


5

Starts automatically with another process id means that it is a different process. Thus there is a parent process, which monitors its children, and if one dies, it respawns it again. If you want to stop the service completely, find out how to stop the parent process. Killing it with SIGKILL is of course one of the options, but probably not The Right OneTM, ...


0

I do not believe you can send a process to the dwm process as parent. But if you could start a screen or shell as a child process of dwm, then you could reparent your desired processes into that. See this link for details: http://monkeypatch.me/blog/move-a-running-process-to-a-new-screen-shell.html


1

Commands on the right hand side of a pipe are run in a subshell - therefore, their $BASHPID is different.


1

I believe /proc/pid/limits is the file you should check. For example, I have the below entry for one process in my system. Max open files 50 50 files


5

You can use the wait shell built-in to accomplish this. The wait builtin simply causes the shell to pause waiting for background jobs to complete. You can either pass it a specific job to wait for, or have it wait for all jobs. For example: echo $(date): starting sleep 5 & echo $(date): do something else wait echo $(date): background job finished ...


6

On Linux, the file is not locked even when a program is writing to it (unlike windows). To check if the process is completed, use: while [[ 1 ]]; do pgrep dbprocess &>/dev/null if [[ $? -eq 0 ]]; then echo still running else echo finished # start ftp transfer fi sleep 2 done To check if the process has the file open, you can ...


1

The biggest negative is the potential extra load that it may introduce to a server. Now saying that it's typically enabled on CentOS and Fedora, and it's designed to consume as small a footprint as possible so that it can collect these types of detailed audits. So I would fully expect that it won't cause you any issues, assuming the logs are being handled ...


2

For the documented answer, we need to look at the man page for the system call that the exec family of functions calls, execve: By default, file descriptors remain open across an execve(). File descriptors that are marked close-on-exec are closed; see the description of FD_CLOEXEC in fcntl(2). So, if the process did not set the close-on-exec flag in ...


1

Yes, using exec and inheriting the same pid as the parent means the child keeps the pipe connections by default, so long as file-descriptors are not marked close-on-exec (which might be done via fcntl, see Mark Plotnick's answer). I was on the verge of self answering with empirical data when I wrote up my question, and I followed through with a self-answer, ...


3

Have a look at cgroups, it should provide exactly what you need - CPU reservations (and more). I'd suggest reading controlling priority of applications using cgroups. That said, put the important yet often idle processes into group with allocated 95% of CPU and your other applications into another one with allocated 5% - you'll get (almost) all of the power ...


0

@muru cpulimit looks way better I think you got mixed up with nice nice ranges at least from -20 resulting favorable scheduling through 19, least favorable. The default behavior is to increase the niceness by 10 which you did. But here is the issue: a nice should not be confused with a scheduling priority, which lets applications determine the order in ...


0

Coincidence: I just came across the cpulimit command. It limits the CPU usage of a process (to a certain %, for example). An example from the manpage: # cpulimit -l 20 firefox Launch Firefox web browser and limit its CPU usage to 20%


2

Try this: dialog --keep-window --begin 0 0 --tailboxbg /var/log/process1.log 20 110 \ --and-widget --keep-window --begin 0 120 --tailboxbg /var/log/process2.log 20 110 \ --and-widget --begin 21 100 --msgbox "Press Enter to exit." 5 25 Adjust the numbers to fit your need. I had to use the msgbox to keep dialog alive.



Top 50 recent answers are included