09-02-2001
check my code?? running shell from c?
Hi mates,
i am trying to run a shell command from my C program in this case let is say the "ls" command. It copiles it okay, and even creates the new fork too. But seems to nothing is happening i mean it is not showing the result of the "ls" command.
I don't know wat i am doing wrong. Any comment will be appreciated.
abdul
#include <unistd.h>
#include <sys/wait.h>
#include <stdio.h>
int p_id;
int child_status;
int cpid;
main()
{
cpid=fork();
switch (cpid)
{
case -1:
perror("fork");
exit(1);
case 0:
printf("The fork is successful!\n");
system('ls');
exit(0);
default:
wait(&child_status);
}
}
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Does anyone know if there is a UNIX-tool available that constantly will check if (some specific) deamons are running and will notify (via email) if one has failed/stopped?
I searched the web, but so far didn't find anything. (3 Replies)
Discussion started by: W2W
3 Replies
2. Shell Programming and Scripting
Hi
I want to check whether specific process is running or not through a shell script.
ps -ef | grep will tell me this, i tried this way in shell
cnt =`ps -ef| grep xyz | awk '{ END {print NR}}`
if it return two rows, job is running else not.
Is there any better way of doing this. (3 Replies)
Discussion started by: agp
3 Replies
3. UNIX for Advanced & Expert Users
I want to write a unix shell script that will check if a process (say debu) is running in the server or not. If no , then send a mail to the corresponding person to start the process??? (2 Replies)
Discussion started by: debu
2 Replies
4. OS X (Apple)
What I want my script to do is to run a command in Terminal and close that same Terminal window when the process is complete.
Of course I could ad a delay of 6 seconds to complete the process, but it may not be enough every time.
To simplify my question, this is what I want to achieve.... (9 Replies)
Discussion started by: ShadowofLight
9 Replies
5. Solaris
Hi,
I put this at start of my shell (korn shell) to be sure that the shell is not already running and sometimes it fails and says that it is already running which is not true !
sleep 1
/usr/bin/ps -ef | /usr/bin/grep "$0" | /usr/bin/egrep -v grep>$LOGDIR/$0.res
isup=$(cat $LOGDIR/$0.res|wc... (4 Replies)
Discussion started by: zionassedo
4 Replies
6. Shell Programming and Scripting
Hi Experts,
I am checking how to get day in Perl.
If it is “Monday” I need to process…below is the pseudo code.
Can you please prove the code for below condition.
if (today=="Monday" )
{
while (current_time LESS THAN 9:01 AM)
... (1 Reply)
Discussion started by: ajaypatil_am
1 Replies
7. Shell Programming and Scripting
hi guys
we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies
8. Shell Programming and Scripting
Hi Everyone,
Is there any way ( generic) to check syntax of Shell Scripts without running it?? (4 Replies)
Discussion started by: roy121
4 Replies
9. Shell Programming and Scripting
I want to check how many processes are running with same names and get their respective counts.
ps -ef|grep -Eo 'process1|process2|process3| '|sort -u | awk '{print $2": "$1}'
Output would look like :
$ ps -ef|grep -Eo 'process1|process2|process3| '|sort | uniq -c | awk '{print $2":... (8 Replies)
Discussion started by: simpltyansh
8 Replies
10. Shell Programming and Scripting
I am working on script. it reads a file which contains multiple lines
Ex;
curl --write-out %{http_code} --silent --output /dev/null http://hostname:port/input=1
curl --write-out %{http_code} --silent --output /dev/null http://hostname:port/input=2
curl --write-out %{http_code} --silent ... (2 Replies)
Discussion started by: oraclermanpt
2 Replies
LEARN ABOUT MOJAVE
platform::shell
platform::shell(n) Tcl Bundled Packages platform::shell(n)
__________________________________________________________________________________________________________________________________________________
NAME
platform::shell - System identification support code and utilities
SYNOPSIS
package require platform::shell ?1.1.4?
platform::shell::generic shell
platform::shell::identify shell
platform::shell::platform shell
_________________________________________________________________
DESCRIPTION
The platform::shell package provides several utility commands useful for the identification of the architecture of a specific Tcl shell.
This package allows the identification of the architecture of a specific Tcl shell different from the shell running the package. The only
requirement is that the other shell (identified by its path), is actually executable on the current machine.
While for most platform this means that the architecture of the interrogated shell is identical to the architecture of the running shell
this is not generally true. A counter example are all platforms which have 32 and 64 bit variants and where a 64bit system is able to run
32bit code. For these running and interrogated shell may have different 32/64 bit settings and thus different identifiers.
For applications like a code repository it is important to identify the architecture of the shell which will actually run the installed
packages, versus the architecture of the shell running the repository software.
COMMANDS
platform::shell::identify shell
This command does the same identification as platform::identify, for the specified Tcl shell, in contrast to the running shell.
platform::shell::generic shell
This command does the same identification as platform::generic, for the specified Tcl shell, in contrast to the running shell.
platform::shell::platform shell
This command returns the contents of tcl_platform(platform) for the specified Tcl shell.
KEYWORDS
operating system, cpu architecture, platform, architecture
platform::shell 1.1.4 platform::shell(n)