How to determine whether a process is running or not and make use it to make a conditional shell script?

1

Sometimes I run GDB using the "--pid" command argument, and sometimes I use gdb to "run" a program. If I want 1 gdb command file to use in both situtations, I have a problem because you cannot continue a process that is not running, and you cannot type "run" when a process is running.

I.e. here's a simple command file:

br main.c:30 commands p foo c end # what can i put here, so that the command file will work in both situations?

If I put "run" in the command file, when I attach to a process, it will actually stop the current process and run a new one (I definitely don't want this). If I put "c" in the command file, then when I try to use "gdb --command=commandfile --args process arg1 arg2", then it will say "there's no process running".

This is useful because if I have a complicated set of commands I want to use, it is useful to have the flexibility to be able to load them on both processes before they start and on processes which are already running, without...

0 0
2

The git-diff man page describes two options of relevance here:

--quiet Disable all output of the program. Implies --exit-code.

and

--exit-code Make the program exit with codes similar to diff(1). That is, it exits with 1 if there were differences and 0 means no differences.

Therefore, a robust approach would be to run

git diff --quiet; nochanges=$?

The shell variable nochanges will be equal to 0 (i.e. true) if there are no changes, and 1 (i.e. false) otherwise.

You can then use the value of nochanges in conditional statements as follows:

if [ $nochanges -eq 0 ]; then # there are no changes else # there are changes fi

Alternatively, if you don’t need to store the exit status in a variable, you can do:

if git diff --quiet; then # there are no changes else # there are changes fi

Edit: Since git diff is a porcelain Git command and you want to do things programmatically, you should probably use the plumbing Git command called git...

0 0
3
...
0 0
4


Hey, Scripting Guy! How can I determine whether a domain is in mixed mode or native mode?

-- WW

Hey, WW. When you listen to a Seattle Mariners game on the radio one of the regular features is “Stump the Broadcasters.” The premise to Stump the Broadcasters is that listeners send in a baseball question to be asked of the Mariners broadcasters. If you can “stump the broadcasters” (that is, if you ask a question that the broadcasters can’t answer) then you win a fabulous prize. Pretty simple, huh?

The only problem with Stump the Broadcasters is that people send in such silly questions: “Who holds the major league record for most career home runs?” To be honest, you just want to grab these people, shake them, and say, “What’s wrong with you? Don’t you want to win the fabulous prize? Even people who don’t know anything about baseball know that Hank Aaron holds the record for most career home runs. Holy smokes!”



If you want to stump...

0 0
5

Questions:

How do i detect the bitness (32-bit vs. 64-bit) of the Windows OS in VBScript?

I tried this approach but it doesn’t work; I guess the (x86) is causing some problem which checking for the folder..

Is there any other alternative?

progFiles=”c:\program files” & “(” &
“x86” & “)”

set
fileSys=CreateObject(“Scripting.FileSystemObject”)

If fileSys.FolderExists(progFiles) Then

WScript.Echo "Folder Exists"

End If

Answers:

You can query the PROCESSOR_ARCHITECTURE. A described here, you have to add some extra checks, because the value of PROCESSOR_ARCHITECTURE will be x86 for any 32-bit process, even if it is running on a 64-bit OS. In that case, the variable PROCESSOR_ARCHITEW6432 will contain the OS bitness. Further details in MSDN.

Dim WshShell Dim WshProcEnv Dim system_architecture Dim process_architecture Set WshShell = CreateObject("WScript.Shell") Set WshProcEnv = WshShell.Environment("Process")...
0 0
6

Code:

ps -ax |grep process-name A couple of complications with this idea:
If the program is running already, sometimes you'll get two lines, containing these two strings:

Code:

process-name ps -ax | grep process-name ... and sometime you won't. So if the program isn't running already, sometimes you'll get this line:

Code:

ps -ax | grep process-name and sometimes you won't. You can fix this problem by saying:

Code:

ps -ax | grep program-name | grep -v grep Even better yet, if you're going to do this command, leave out the grep entirely, and parse the output of the ps command yourself, in your C program.It's entirely possible that someone else is running a program called program-name-xxx or program-name-2.0 or something. If you're parsing the ps command yourself, you can figure out how to avoid this problem.You'll be firing up at least one new process, the ps process, just to check for duplicate running. Extra overhead. This is a really...
0 0
7

A PID is an acronym for process identification number on a Linux or Unix-like operating system. A PID is automatically assigned to each process when it is created. A process is nothing but running instance of a program and each process has a unique PID on a Unix-like system.

The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.

Find out process pid

Type the following ps command to display all running process:

# ps -aux | less OR # ps aux | less

Where,

A : Select all processes u : Select all processes on a terminal, including those of other users x : Select processes without controlling ttys

By use ps command we can get process name

# ps aux | grep {process-name}

For example lets find httpd process (nginx pid) is running or not:

# ps aux | grep nginx root 1494 0.0 0.0 103328 900 pts/1 S+ 10:41 0:00 grep nginx root ...
0 0
8

Any solution that uses something like ps aux | grep abc or pgrep abc are flawed.

Why?

Because you are not checking if a specific process is running, you are checking if there are any processes running that happens to match abc. Any user can easily create and run an executable named abc (or that contains abc somewhere in its name or arguments), causing a false positive for your test. There are various options you can apply to ps, grep and pgrep to narrow the search, but you still won't get a reliable test.

So how do I reliably test for a certain running process?

That depends on what you need the test for.

I want to ensure that service abc is running, and if not, start it

This is what init and upstart are for. They'll start the service and ensure its pid gets stored in a pidfile. Try to start the service again (via init or upstart) and it will check the pidfile, and either start it if it's not there, or abort if it's already running. This...

0 0
9

Every process will be listed in the output of ps aux; whether running, sleeping, zombie or stopped.

However, in your case, since you ran the process using sh abc.sh, sh is the application(shell) that is running and not abc.sh. Hence, ps aux will not contain the process abc.sh because of which grep could not yield any result.

So, the correct way you should have used it is as:

ps aux | grep sh

This may also return you other process that are running having the string sh anywhere in their output of ps aux.

You should note that the process will be "running" when the output of ps aux has its STAT as R. If it is something other than that, it is not running at the instance you fired the command to check the running processes. The different process states can be found in the man page for ps:

D uninterruptible sleep (usually IO) R running or runnable (on run queue) S interruptible sleep (waiting for an event to complete) T stopped, either by a job control...
0 0
10


General

Q:

What is this FAQ about?

A:

This is a FAQ for The ACE ORB (TAO), an open-source CORBA-compliant ORB born of research at Washington University in St. Louis' Center for Distributed Object Computing (http://www.cse.wustl.edu/~doc/). If your question isn't answered here, you might want to check out the following links:

We at OCI provide commercial-grade support for this ORB, along with documentation and consulting services (see our web page at http://www.ociweb.com for more details), and provide the site and content of this FAQ as a free service to the TAO community.

If you have questions, and especially if you have answers to them, please send them to support@ociweb.com for inclusion in this FAQ! Let us know whether you'd like to be credited with the answer and, if so, how.

Q:

Where can I find the source code for the examples in the TAO Developer's Guide?;

A:

The source code for all the examples in...
0 0
11

We respect its storied history, and value the contributions of its many readers, but we can no longer support it at the level it deserves. There’s a wealth of great information here that many will find useful, so we've elected to maintain it in a read-only form. Thanks for your many years of attention and everything you've done to make the site such a valuable resource.


You rated: 2 / 5 (3 votes cast)

[72 views]


I sometimes find the Java setup on my various Apple devices to be a mystery.

Recently, I was trying to get a Java applet to run in the same way on 2 iMacs and my MacBook Air. The applet is a simple vpn client from Juniper that lets me access a Citrix Desktop from any Mac that I can install the Citrix receiver client on so I can work on 'Company stuff' from a large screen iMac when I'm sat at home or from my MacBook when I'm on the road (it works fine over 3/4G).

The first thing is that you...

0 0
12

Please help

I am trying to apply feature matching in digital image using keypoints. In this task I'm using CNNs. However, I'm still new in this area, so I need your help. Any one knew how to do so, please contact me. Also if some one has a code can be modified also he will be appreciated if he can share that.

All the best

Back to top

What is a cell array?Edit

A cell is a flexible type of variable that can hold any type of variable. A cell array is simply an array of those cells. It's somewhat confusing so let's make an analogy. A cell is like a bucket. You can throw anything you want into the bucket: a string, an integer, a double, an array, a structure, even another cell array. Now let's say you have an array of buckets - an array of cells or a "Cell Array". Each bucket can contain something different, or they might all contain the same type of variable. Bucket 1 could contain a string, while bucket 2 could contain an image (array of uint8's),...

0 0
13

Introduction

OpenVPN is a full-featured SSL VPN which implements OSI layer 2 or 3 secure network extension using the industry standard SSL/TLS protocol, supports flexible client authentication methods based on certificates, smart cards, and/or username/password credentials, and allows user or group-specific access control policies using firewall rules applied to the VPN virtual interface. OpenVPN is not a web application proxy and does not operate through a web browser.

OpenVPN 2.0 expands on the capabilities of OpenVPN 1.x by offering a scalable client/server mode, allowing multiple clients to connect to a single OpenVPN server process over a single TCP or UDP port. OpenVPN 2.3 includes a large number of improvements, including full IPv6 support and PolarSSL support.

This document provides step-by-step instructions for configuring an OpenVPN 2.x client/server VPN, including:

The impatient may wish to jump straight to the sample configuration files:

...
0 0