Programming :: Skip Execution Of A Function In A Script?
Mar 15, 2011
I have a bash script which is composed of different functions.I want to able to select which functions to be executed when i run the script, for that i thought about using a flag in the function. but i dont know how to skip the function whose flag is set to zero.
I am doing some Linux kernel programming for my research project. I need to record the timestamp (by using cpuid and rdtsc) when an interrupt handler (top half) is first invoked. Due to the time critical nature of the problem itself, I have to do the timestamping inside the interrupt handler itself (the first operation when the handler is called). However, I understand that tasks that are not so time critical should be deferred to a tasklet function (bottom half) for processing because other interrupts are disabled in a (top-half) interrupt handler. I am currently out of idea on how I can pass the timestamp information that I have obtained in the interrupt handler to the corresponding tasklet function.
I would like to read an input from keyboard using getchar. However, if no input (No Carriage return/new line none whatsoever) is given after say, 5 seconds, I would like to skip the getchar and move on. How do I do this in C. I'm using GNU compiler set.
I want to list "/home/user/tmp" but descend only in "test" "statfs" and "statvfs" don't offer any information to discern if a dir was mounted twice. One solution would be to read "/etc/mtab" (as "find" command does it) and perform some checks, but I think that this is pretty expensive (one has to read /etc/mtab every time one encounters a dir; if this file is read only when program starts, a mount could occur in between reads, so that the program will be inaccurate). Another solution would be to filter kernel events (via libudev or Netlink) and do this reading of /etc/mtab only when a MOUNT event was issued.
GNU/Linux kernel 2.6, Slackware 12.0 MPlayer 1.0rc2-4.1.2 GNU Bash 3.1.17
I've got a set of MP3 files on dir .../foo/ and I want mplayer to play them sequencely but skipping some of them. If I run 'mplayer *' this will do but ofcourse won't skip any files. I think a shell script could be written to do that. It would be something like this (using some pseudocode):
#!/bin/bash #After an example from Intro_Linux by M. Garret. LIST=$(ls *.mp3)
How do I make getchar() skip a leading space? The situation I am looking is this: I print a prompt that ends in a space printf("Input: ");and then when I use getchar() to read the text that was typed after the prompt, it appears to process the trailing space as a leading space that belongs to the input.
how can the space be skipped, preferably without inserting code that explicitly checks whether I'm reading the first character or not. I have already found out that I can skip such a space using scanf scanf (" %c", &ch); where the leading space in the format string eliminates leading spaces from the input string. That is the sort of thing I have in mind.
And achieve something like this when I view the contents of test2.txt:
Hello World Your boss is Me
The problem is, it's not that easy to achieve. I don't want to do the "echo Hello $USER1 >> test2.txt" because I'm planning to implement this on a MB-sized text file.
I'm trying to save the output of the script I wanna run but for some reason I cant manage to do it with "script.sh > Output_4.txt"
The thing is that the script was already run and it extracted some directories so when I try to run it again (to save the log to a Output_4.txt) bash says (see screen-capture) and of course the log's empty!!!!
I went to an interview last week and there was this guy who asked a simple question that i have been trying to solve for a couple of days. I tried google but i just cant get the search keywords right. The result were just useless. Well, the question is : "How can we allocate a limited memory to a process before we start its execution" well, the question is related to an X11 system so may be some flags must be set to limit its memory.
In gui validation if user enters string in integer requiring field, a dialog box pops out. So on clicking the button i want to stop the program execution and return to the previous jframe(either the same one or newly created object of it).
How can i handle this in java. I tried calling main(); but it doesn't work. Also System.exit(0); doensn't work.
As part of my job I often have to write queries in Oracle (10g) and I am experienced enough to see where I should be using an index where possible etc. Most of the time I just let the CBO come up with the best plan however sometimes it obviously doesn't!Now, I know in general that full scans of large tables aren't good however I don't fully understand an execution plan - ie, I could not look at a complex piece of code, look at it's plan and say "oh, the reason that is performing badly there is because the SBO has chosen to use nested loops rather than a hash join, so if I hint it then it will run quicker!" - this ultimately is where I'm trying to get to
I looked on the net for such function or example and didin't find anything, thus after having made one i guess it would be legitimate to drop it to see what others thinks of it.
#!/bin/bash addelementtoarray() { local arrayname=$1
Do you know how to write a shell script that executes say 4 instances of the same program in different directories at the same time, and once ONE instance completes it executes a new instance of that program in a new directoryd so on, until 100 instances have been executed, each in their own directory
I have a test framework written in tcl which i run for 5-6 hours.Now i want to retrieve the pid of the process (execution using framework) as first few line of the script and do some processing.
I'm trying to figure out how to continue execution of a Python program while a background task is going on.
In bash, it is adding "&" to the end as in:
Code: #! /bin/bash find / -iname "*.py" > /tmp/all_pys & echo "looking for all python scripts and putting them in /tmp/all_pys" (yes, I know I could just put the echo BEFORE the find but I just use it for example)
Say I do that in python (not necessarily running the shell, but perhaps using scriptutil.ffind or something similar), but want to allow the user to be doing something else while running that search in the background, how would I thread, fork, subprocess (not to be confused with the module and Popen) [or whatever I should call it] that?
fit a surface i.e. W(x,y) using svdfit() provided by "Numerical Recipes in C". svdfit() is written for curve fitting and not for surface fitting.But one can use svdfit(), as claimed by authors of NR book, to do surface fitting. On page 680 of NR book, authors have given a hint on how to use svdfit() for fitting a surface. But I have not understood it.This link may be helpful (Chapter 15 th is relevant here.):[URL]This is my problem:
Code: I have a set of 100 numbers. I want to fit a 2-Dimensional function W(x,y) to these numbers.
I have a question about calling an asm function from C....It doesn't work unless I create an asm variable to hold the value of the function in....Why?Here's the code that doesn't work...
asmfile.s - version one Code: .section .data mydata: .ascii "this is the message! .equ mylen, . - mydata
I want to use backtrace() function to debug a crash issue. I tried this sample code to see how backtrace works. backtrace() function always returns 0 with the below code. Is there any kernel configuration that needs to be set for proper working of backtrace?
#include <execinfo.h> #include <stdio.h> #include <stdlib.h> /* Obtain a backtrace and print it to stdout. */ void print_trace (void)
Can you offer me the code about fmod() in C. I want to know how this function work, i am very interested in it because i have no idea to implement it, i want to know... how to write the function... not 'how to use the function' can anyone post the source codes of this function here?
i have an open source application that was developed in C++ (it uses objects and namespaces all over the place). I also have another application that was developed in C. Now i am trying to insert the code made in C into C++ application, but when i do that , i get this error on compilation of the source code:
Code: error: 'mpi_init_vars' was not declared in this scope the function mpi_init_vars() is not part of object oriented programming and it doesn't belong to any scope, it was compiled into an object file and i am linking it with all objects of C++ application.
How can invoke the C function from C++ object oriented code?
Code: #!/bin/sh #System commands and other configurable. IPT=/sbin/iptables IP6T=/sbin/ip6tables IPST=/usr/sbin/ipset MODP=/sbin/modprobe GET=/usr/bin/wget INT_NET=192.168.1.0/24 .....
I can find lots of tutorials in how to use if, then, else. However, how do I define a variable inside the function? SEE>> Code: for c in $ISO Also, am I using the 'test' command correctly( -/+ week as valid test)?
I am doing a web site program and what I need is to call a C program in the PHP cloud.Do u think it would be possible? The web site would get the user input from PHP UI and pass to the C program , the C program would process the function with the user input and output the a PHP page.
Code: return ((unsigned int)(unsigned long)base & TBASE_DEFERRABLE_FLAG); What is the above function returning.I am not clear with definition of what is being returned in the above code.
i want to compile function c in java and compile library is success.. when i call the library in java and error is :
Exception in thread "main" java.lang.UnsatisfiedLinkError: no libfunc.so in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1689) at java.lang.Runtime.loadLibrary0(Runtime.java:823) at java.lang.System.loadLibrary(System.java:1028)