Measure thread execution (in C, unix)

Probably a lack of environment, as no #!/usr/bin/perl -w as the first line of ./hash.pl would fail interactively, and most commands do not care there is no tty. For instance, ps -f is tied to your tty, ps -fp $pid is not, nor ps -fe | grep -c <pattern>, ps -fu <user_id>!

Put a "set >/tmp/mycronenv" into the script, let cron run it, and compare it to "set >/tmp/mytermenv" using diff.

1 Like

so is there a reason why script wont run in cron but runs normally in cmd line (even with its dodgy code!)???

Note: two threads on identical topic merged. Please do not post twice on the same topic - this kind of hodge-podge results from doing that.

We also have a rule against this, for that very reason. However it is too late to close the extra thread.

---------- Post updated at 09:54 ---------- Previous update was at 09:51 ----------

It appears I have really hosed things up by merging the wrong threads My apologies.
There is no way available to me to remedy the problem.

Environment (exported variables) is #1. When you log in, all sorts of scripts run before your shell prompt arrives, setting your environment so the shell is useful. The cron and rsh/ssh waste no time on this, so you have to explicitly add the missing environment.

Lack of a tty is usually less of a problem, so it is #2.

Some programs get upset when the default stdin cannot be read or gets EOF immediately. Since there is no tty, there is no keyboard, there can be no input but that supplied in the scripting.

Hi DGPickett

See results of diff as you suggetsed above in Post #21

alps$ diff mycronenv mytermenv
0a1
> EDITOR=vi
3a5
> LD_LIBRARY_PATH=/usr/local/lib:/usr/local/ssl/lib:/usr/local/mysql/lib:/usr/local/mrtg-2/lib:/usr/local/mrtg-2/lib:/usr/share/lib:/usr/openwin/lib:/usr/openwin/platform/sun4u/server/lib:/usr/sadm/lib/smc/lib:/usr/local/lib:/etc/lib:/etc/security/lib:/lib:/opt/SUNWits/Graphics-sw/xil/lib:/usr/sadm/smc/lib:/usr/sadm/lib:/usr/ccs/lib:/usr/openwin/platform/sun4u/server/lib:/oracle_install/product/10.2.0/lib32:/usr/sfw/lib
4a7
> MAIL=/var/mail//capopt
5a9
> OLDPWD=/home/it/capopt
7,8c11,22
< PATH=/usr/bin:
< SHELL=/usr/bin/sh
---
> ORACLE_BASE=/oracle_install
> ORACLE_HOME=/oracle_install/product/10.2.0
> ORACLE_TERM=vt100
> PATH=/usr/bin:/oracle_install/product/10.2.0/bin:/bin:/usr/sbin:/usr/bin:/usr/dt/bin:/usr/openwin/bin:/usr/local/bin:/usr/sfw/bin
> PS1=alps$
> PWD=/home/it/capopt/APNRD/S30
> SHELL=/bin/sh
> SHLVL=1
> SSH_CLIENT=172.27.102.22 64452 22
> SSH_CONNECTION=172.27.102.22 64452 192.168.198.110 22
> SSH_TTY=/dev/pts/4
> TERM=xterm
9a24,26
> USER=capopt
> VISUAL=vi
> _=./condenseS30.sh 

Both ld_library_path and path are critical to everything, and if you want Oracle, you have to get those, too. You can 'source' your .profile or make a special env file for cron to source. If .profile works but complains in an ugly way, just redirect it away (. $HOME/.profile >/dev/null 2>&1).

Don't forget to export EACH_VAR_NAME, which can be the same line if not sh (export THIS_VAR_NAME=THIS_VAR_VALUE) ! You really want to move to ksh or bash, sh is pretty retro!

im changing script from

#!/usr/bin/sh

to

#!/bin/sh

and praying hard!

Sorry but you're problem has no link with first problem (measuring thread execution) and I will never have answer if this topic speaks about another problem.
Could moderator splits this message to have separate discussions please ?

Iknew parying was a waste of time..........

One dir is a symbolic link to the other, except in later Solaris, where one dir supports boot and the other supports more complex apps, so you have to do both / and /usr in PATH, LD_LIBRARY_PATH.

Without LD_LIBRARY_PATH, dynamically linked programs cannot find their libs.

Thnaks DG, can you advise as how I rectify?

For thread timers, beyond gethrtime(), you tend to get platform dependent. Someone should POSIX up a double float time and interval time function set. This mentions an assembler call:
http://fixunix.com/bsd/87936-high-resolution-interval-timers.html

-------------- For cron script problem ---------- two threads together makes you double post ----------------

Somewhere early, you need to include explicitly or in a 'sourced' file ( . file_full_path ) these lines:

PATH= . . . .
export PATH
LD_LIBRARY_PATH= . . . .
export LD_LIBRARY_PATH

and any other variables you need, like the Oracle ones, using the values from your terminal set. The sh form above is also ksh/bash compatible.

FYI I have now being posting into original thread under Solaris!